# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549007 | 2022-04-14T23:57:48 Z | LucaDantas | Railway Trip (JOI17_railway_trip) | C++17 | 2000 ms | 3284 KB |
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 1e5+10; int a[maxn], l[maxn], r[maxn], dist[2][maxn]; void bfs(int s, int k) { for(int i = 0; i < maxn; i++) dist[k][i] = 0x3f3f3f3f; dist[k][s] = 0; queue<int> q; q.push(s); while(q.size()) { int u = q.front(); int d = dist[k][u]; q.pop(); for(int rep = 0; rep < 2; rep++, swap(l[u], r[u])) if(dist[k][l[u]] > d+1) q.push(l[u]), dist[k][l[u]] = d+1; } } int main() { int n, k, q; scanf("%d %d %d", &n, &k, &q); for(int i = 0; i < n; i++) scanf("%d", a+i); l[0] = 0; for(int i = 1; i < n; i++) { l[i] = i-1; while(a[l[i]] < a[i]) l[i] = l[l[i]]; } r[n-1] = n-1; for(int i = n-2; i >= 0; i--) { r[i] = i+1; while(a[r[i]] < a[i]) r[i] = r[r[i]]; } while(q--) { int x, y; scanf("%d %d", &x, &y); --x, --y; bfs(x, 0); bfs(y, 1); int ans = 0x3f3f3f3f; for(int i = 0; i < n; i++) ans = min(ans, dist[0][i] + dist[1][i] - 1); printf("%d\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 980 KB | Output is correct |
2 | Correct | 2 ms | 980 KB | Output is correct |
3 | Correct | 2 ms | 1084 KB | Output is correct |
4 | Correct | 2 ms | 980 KB | Output is correct |
5 | Correct | 2 ms | 1108 KB | Output is correct |
6 | Correct | 2 ms | 1108 KB | Output is correct |
7 | Correct | 3 ms | 1108 KB | Output is correct |
8 | Correct | 2 ms | 980 KB | Output is correct |
9 | Correct | 2 ms | 1084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1108 KB | Output is correct |
2 | Correct | 29 ms | 2388 KB | Output is correct |
3 | Correct | 26 ms | 2388 KB | Output is correct |
4 | Correct | 20 ms | 2484 KB | Output is correct |
5 | Correct | 20 ms | 2520 KB | Output is correct |
6 | Correct | 21 ms | 2584 KB | Output is correct |
7 | Correct | 26 ms | 2728 KB | Output is correct |
8 | Correct | 128 ms | 2516 KB | Output is correct |
9 | Correct | 84 ms | 2724 KB | Output is correct |
10 | Correct | 88 ms | 2648 KB | Output is correct |
11 | Correct | 71 ms | 2832 KB | Output is correct |
12 | Correct | 66 ms | 2828 KB | Output is correct |
13 | Correct | 81 ms | 2804 KB | Output is correct |
14 | Correct | 76 ms | 2836 KB | Output is correct |
15 | Correct | 76 ms | 2800 KB | Output is correct |
16 | Correct | 62 ms | 2772 KB | Output is correct |
17 | Correct | 18 ms | 2804 KB | Output is correct |
18 | Correct | 18 ms | 2852 KB | Output is correct |
19 | Correct | 32 ms | 2708 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2054 ms | 2872 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2059 ms | 3284 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |