# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
620752 | 2022-08-03T08:49:11 Z | 조영욱(#8520) | Railway Trip (JOI17_railway_trip) | C++17 | 2000 ms | 20180 KB |
#include <bits/stdc++.h> using namespace std; int n,k,q; int lev[100001]; const int INF=1e9; vector<int> vec[100001]; typedef pair<int,int> P; vector<P> adj[100001]; int tree[100001]; int dist[100001]; bool vis[100001]; int sum(int i) { int ret=0; while (i>0) { ret+=tree[i]; i-=(i&-i); } return ret; } void update(int i,int val) { while (i<=n) { tree[i]+=val; i+=(i&-i); } } void dijk(int st) { for(int i=1;i<=n;i++) { dist[i]=INF; vis[i]=false; } priority_queue<P,vector<P>,greater<P>> pq; pq.push(P(0,st)); dist[st]=0; while (!pq.empty()) { int now=pq.top().second; pq.pop(); if (vis[now]) { continue; } vis[now]=true; for(int i=0;i<adj[now].size();i++) { int nt=adj[now][i].first; if (dist[nt]>dist[now]+adj[now][i].second) { dist[nt]=dist[now]+adj[now][i].second; pq.push(P(dist[nt],nt)); } } } } int main(void ) { scanf("%d %d %d",&n,&k,&q); for(int i=1;i<=n;i++) { scanf("%d",&lev[i]); vec[lev[i]].push_back(i); } set<int> s; for(int i=k;i>0;i--) { for(int j=0;j<vec[i].size();j++) { s.insert(vec[i][j]); } for(int j=0;j<vec[i].size();j++) { auto iter=s.lower_bound(vec[i][j]); if (next(iter)!=s.end()) { iter++; int now=(*iter); adj[vec[i][j]].push_back(P(now,1)); adj[now].push_back(P(vec[i][j],1)); iter--; } if (iter!=s.begin()) { iter--; int now=(*iter); adj[now].push_back(P(vec[i][j],1)); adj[vec[i][j]].push_back(P(now,1)); } } for(int j=0;j<vec[i].size();j++) { s.insert(vec[i][j]); } } for(int ind=0;ind<q;ind++) { int a,b; scanf("%d %d",&a,&b); if (a>b) { swap(a,b); } dijk(a); printf("%d\n",dist[b]-1); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 4 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 4952 KB | Output is correct |
5 | Correct | 3 ms | 4948 KB | Output is correct |
6 | Correct | 4 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 5076 KB | Output is correct |
2 | Correct | 471 ms | 16796 KB | Output is correct |
3 | Correct | 549 ms | 16884 KB | Output is correct |
4 | Correct | 582 ms | 16796 KB | Output is correct |
5 | Correct | 630 ms | 16860 KB | Output is correct |
6 | Correct | 756 ms | 17080 KB | Output is correct |
7 | Correct | 1128 ms | 19060 KB | Output is correct |
8 | Correct | 198 ms | 15748 KB | Output is correct |
9 | Correct | 321 ms | 18012 KB | Output is correct |
10 | Correct | 267 ms | 17012 KB | Output is correct |
11 | Correct | 670 ms | 17860 KB | Output is correct |
12 | Correct | 696 ms | 17536 KB | Output is correct |
13 | Correct | 683 ms | 17360 KB | Output is correct |
14 | Correct | 610 ms | 17764 KB | Output is correct |
15 | Correct | 592 ms | 17408 KB | Output is correct |
16 | Correct | 570 ms | 17364 KB | Output is correct |
17 | Correct | 687 ms | 17744 KB | Output is correct |
18 | Correct | 727 ms | 17616 KB | Output is correct |
19 | Correct | 651 ms | 20180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2073 ms | 16608 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2081 ms | 19212 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |