Submission #959200

# Submission time Handle Problem Language Result Execution time Memory
959200 2024-04-07T16:19:03 Z Abito Railway Trip (JOI17_railway_trip) C++17
5 / 100
4 ms 676 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++){
            int w=0;
            for (int k=i+1;k<j;k++) w+=(a[k]>=min(a[i],a[j]));
            adj[i].pb({j,w+1});
            adj[j].pb({i,w+1});
        }
    }
    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 4 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 676 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
# 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 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -