# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782424 | 2023-07-14T00:34:06 Z | GusterGoose27 | Ancient Books (IOI17_books) | C++17 | 118 ms | 11240 KB |
#include "books.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1e6+5; typedef long long ll; typedef pair<int, int> pii; bool vis[MAXN]; int n; int _abs(int v) { return v < 0 ? -v : v; } ll minimum_walk(vector<int> p, int s) { ll ans = 0; n = p.size(); for (int i = 0; i < n; i++) ans += _abs(p[i]-i); if (ans == 0) return 0; vector<pii> intervals; for (int i = 0; i < n; i++) { if (vis[i]) continue; int cur = i; int l = i, r = i; do { l = min(l, cur); r = max(r, cur); vis[cur] = 1; cur = p[cur]; } while (cur != i); if (r > l) intervals.push_back(pii(l, r)); } sort(intervals.begin(), intervals.end()); // they are probably already sorted int curr = intervals[0].second; int mn = 0; if (intervals[0].first <= s && s <= intervals[0].second) mn = n; if (s < intervals[0].first) mn = n; for (int i = 1; i < intervals.size(); i++) { if (intervals[i].first <= s && s <= intervals[i].second) mn = n; assert(curr != intervals[i].first); if (curr > intervals[i].first) { curr = max(curr, intervals[i].second); continue; } ans += 2*(intervals[i].first-curr); curr = intervals[i].second; } if (s > curr) mn = n; for (int i = 0; i < n; i++) if (p[i] != i) mn = min(mn, _abs(i-s)); return ans+2*mn; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 118 ms | 9084 KB | Output is correct |
31 | Correct | 90 ms | 9088 KB | Output is correct |
32 | Correct | 72 ms | 8048 KB | Output is correct |
33 | Correct | 84 ms | 10848 KB | Output is correct |
34 | Correct | 85 ms | 10864 KB | Output is correct |
35 | Correct | 86 ms | 10856 KB | Output is correct |
36 | Correct | 83 ms | 11072 KB | Output is correct |
37 | Correct | 79 ms | 9320 KB | Output is correct |
38 | Correct | 74 ms | 9204 KB | Output is correct |
39 | Correct | 76 ms | 9072 KB | Output is correct |
40 | Correct | 97 ms | 9096 KB | Output is correct |
41 | Correct | 87 ms | 9072 KB | Output is correct |
42 | Correct | 84 ms | 9092 KB | Output is correct |
43 | Correct | 87 ms | 11240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 118 ms | 9084 KB | Output is correct |
31 | Correct | 90 ms | 9088 KB | Output is correct |
32 | Correct | 72 ms | 8048 KB | Output is correct |
33 | Correct | 84 ms | 10848 KB | Output is correct |
34 | Correct | 85 ms | 10864 KB | Output is correct |
35 | Correct | 86 ms | 10856 KB | Output is correct |
36 | Correct | 83 ms | 11072 KB | Output is correct |
37 | Correct | 79 ms | 9320 KB | Output is correct |
38 | Correct | 74 ms | 9204 KB | Output is correct |
39 | Correct | 76 ms | 9072 KB | Output is correct |
40 | Correct | 97 ms | 9096 KB | Output is correct |
41 | Correct | 87 ms | 9072 KB | Output is correct |
42 | Correct | 84 ms | 9092 KB | Output is correct |
43 | Correct | 87 ms | 11240 KB | Output is correct |
44 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 | Halted | 0 ms | 0 KB | - |