# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29027 | 2017-07-18T06:42:04 Z | 시제연(#1172) | Railway Trip (JOI17_railway_trip) | C++11 | 2000 ms | 18692 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; int n, k, q; int l[100100]; vector<int> his[100100]; vector<int> lis[100100]; set<int> s; bool visit[100100]; int bfs(int s, int e) { queue<pii> q; memset(visit,0,sizeof(visit)); q.push(pii(0,s)); visit[s] = 1; while(!q.empty()) { pii tmp = q.front(); q.pop(); int here = tmp.second, d = tmp.first; if (here==e) return d; for (auto &there : lis[here]) { if (visit[there]) continue; q.push(pii(d+1,there)); visit[there] = 1; } } return -1; } void add(int a, int b) { lis[a].push_back(b); lis[b].push_back(a); } int main() { int i; scanf("%d%d%d",&n,&k,&q); for (i=0;i<n;i++) { scanf("%d",&l[i]); l[i]--; his[l[i]].push_back(i); } for (i=k-1;i>=0;i--) { for (auto &v : his[i]) s.insert(v); for (auto &v : his[i]) { auto it = s.upper_bound(v); if (it!=s.end()) add(v,*it); it = s.lower_bound(v); if (it!=s.begin()) add(v,*(--it)); } } for (i=0;i<q;i++) { int a, b; scanf("%d%d",&a,&b); --a; --b; printf("%d\n",bfs(a,b)-1); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7208 KB | Output is correct |
2 | Correct | 0 ms | 7208 KB | Output is correct |
3 | Correct | 0 ms | 7208 KB | Output is correct |
4 | Correct | 3 ms | 7208 KB | Output is correct |
5 | Correct | 0 ms | 7208 KB | Output is correct |
6 | Correct | 0 ms | 7208 KB | Output is correct |
7 | Correct | 0 ms | 7208 KB | Output is correct |
8 | Correct | 0 ms | 7208 KB | Output is correct |
9 | Correct | 0 ms | 7208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7340 KB | Output is correct |
2 | Correct | 169 ms | 16336 KB | Output is correct |
3 | Correct | 209 ms | 16372 KB | Output is correct |
4 | Correct | 266 ms | 16192 KB | Output is correct |
5 | Correct | 326 ms | 16188 KB | Output is correct |
6 | Correct | 359 ms | 16316 KB | Output is correct |
7 | Correct | 453 ms | 17884 KB | Output is correct |
8 | Correct | 119 ms | 15588 KB | Output is correct |
9 | Correct | 169 ms | 16580 KB | Output is correct |
10 | Correct | 126 ms | 16172 KB | Output is correct |
11 | Correct | 296 ms | 16712 KB | Output is correct |
12 | Correct | 276 ms | 16448 KB | Output is correct |
13 | Correct | 339 ms | 16316 KB | Output is correct |
14 | Correct | 319 ms | 16712 KB | Output is correct |
15 | Correct | 283 ms | 16448 KB | Output is correct |
16 | Correct | 289 ms | 16316 KB | Output is correct |
17 | Correct | 239 ms | 16512 KB | Output is correct |
18 | Correct | 216 ms | 16480 KB | Output is correct |
19 | Correct | 223 ms | 18692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2000 ms | 16116 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2000 ms | 17868 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |