# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98931 | 2019-02-27T15:02:39 Z | square1001 | Ancient Books (IOI17_books) | C++14 | 3 ms | 384 KB |
#include "books.h" #include <vector> #include <iostream> #include <algorithm> using namespace std; const long long inf = 1LL << 61; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vector<pair<long long, long long> > cycles; vector<bool> vis(n); long long off = 0; for(int i = 0; i < n; ++i) { if(vis[i]) continue; long long cl = -inf, cr = inf; int pos = i; while(!vis[pos]) { if(pos <= s) cl = max(cl, (long long)pos); if(pos >= s) cr = min(cr, (long long)pos); vis[pos] = true; off += abs(p[pos] - pos); pos = p[pos]; } if(p[i] == i) continue; cycles.push_back(make_pair(cl - s, cr - s)); } sort(cycles.begin(), cycles.end()); /* for(pair<long long, long long> i : cycles) { cout << i.first << ' ' << i.second << endl; } * */ long long ans = inf, cur = 0; for(int i = 0; i <= cycles.size(); ++i) { ans = min(ans, (i != cycles.size() ? -cycles[i].first : 0) * 2 + cur); ans = min(ans, (i != cycles.size() ? -cycles[i].first : 0) + cur * 2); if(i != cycles.size()) cur = max(cur, cycles[i].second); } return ans + off; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 256 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4156' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |