# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
598190 | 2022-07-17T19:05:25 Z | yanndev | Ancient Books (IOI17_books) | C++17 | 2000 ms | 340 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; ll minimum_walk(vector<int> p, int s) { ll ans = 1e9; int n = (int)p.size(); vector<vector<int>> cycles {}; vector<bool> vis (n, false); int last = 0; for (int i = 0; i < n; i++) { if (vis[i]) continue; //ans += abs(i - last); int pos = i; last = i; cycles.push_back({}); while (!vis[pos]) { vis[pos] = true; cycles.back().push_back(pos); //ans += abs(p[pos] - pos); pos = p[pos]; } } //ans += last; vector<int> perm {}; for (int i = 0; i < (int)cycles.size(); i++) perm.push_back(i); do { ll sub = 0; int lst = 0; for (int i = 0; i < (int)cycles.size(); i++) { for (auto& x: cycles[i]) { sub += abs(x - lst); lst = x; } } sub += lst; ans = min(ans, sub); } while (next_permutation(perm.begin(), perm.end())); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2090 ms | 340 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
6 | Halted | 0 ms | 0 KB | - |