Submission #959202

# Submission time Handle Problem Language Result Execution time Memory
959202 2024-04-07T16:25:56 Z Abito Railway Trip (JOI17_railway_trip) C++17
5 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=105;
int a[N],n,q,k,dis[N];
bool vis[N];
vector<pair<int,int>> adj[N];
void dijkstra(int s){
    for (int i=0;i<N;i++) dis[i]=INT_MAX,vis[i]=0;
    dis[s]=0;
    priority_queue<pair<int,int>> pq;
    pq.push({0,s});
    while (!pq.empty()){
        int x=pq.top().S;
        pq.pop();
        if (vis[x]) continue;
        vis[x]=1;
        for (auto u:adj[x]){
            if (dis[u.F]>dis[x]+u.S){
                dis[u.F]=dis[x]+u.S;
                pq.push({-dis[u.F],u.F});
            }
        }
    }return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k>>q;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            if (a[j]<a[i]) continue;
            adj[i].pb({j,1});
            adj[j].pb({i,1});
            break;
        }
        for (int j=i-1;j>0;j--){
            if (a[j]<a[i]) continue;
            adj[i].pb({j,1});
            adj[j].pb({i,1});
            break;
        }
    }
    while (q--){
        int x,y;
        cin>>x>>y;
        dijkstra(x);
        cout<<dis[y]-1<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -