# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782422 | 2023-07-14T00:21:59 Z | GusterGoose27 | Ancient Books (IOI17_books) | C++17 | 1 ms | 212 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); 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 curl = intervals[0].first; int curr = intervals[0].second; for (int i = 1; i < intervals.size(); i++) { assert(curr != intervals[i].first); if (curr > intervals[i].first) { curr = max(curr, intervals[i].second); continue; } ans += 2*(intervals[i].first-curr); curl = intervals[i].first; curr = intervals[i].second; } int 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 | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 | Halted | 0 ms | 0 KB | - |
# | 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 | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 | Halted | 0 ms | 0 KB | - |