# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340983 | 2020-12-28T20:25:53 Z | pggp | Ancient Books (IOI17_books) | C++14 | 1 ms | 364 KB |
#include <bits/stdc++.h> using namespace std; bool used[1000000]; vector < int > P; int N; int cur_cycle; int cycle[1000000]; vector < vector < int > > cycs; vector < int > l_cyc, r_cyc; void dfs(int vertex){ cycle[vertex] = cur_cycle; cycs[cur_cycle].push_back(vertex); used[vertex] = true; if(!used[P[vertex]]){ dfs(P[vertex]); } } long long minimum_walk(vector < int > p, int s){ N = p.size(); P = p; cur_cycle = 0; for (int i = 0; i < N; ++i) { if(!used[i]){ vector < int > v; cycs.push_back(v); dfs(i); cur_cycle++; } } vector < pair < int, int > > f; for (int i = 0; i < cycs.size(); ++i) { int l_cyc = 1000000; int r_cyc = 0; for(int v : cycs[i]){ l_cyc = min(l_cyc, v); r_cyc = max(r_cyc, v); } f.push_back(make_pair(l_cyc, r_cyc)); } sort(f.begin(), f.end()); long long ans = 0; for (int i = 0; i < f.size(); ++i) { //cout << f[i].first << " " << f[i].second << endl; ans += 2 * (f[i].second - f[i].first); } ans += f.size(); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | 3rd lines differ - on the 1st token, expected: '6', found: '7' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | 3rd lines differ - on the 1st token, expected: '6', found: '7' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | 3rd lines differ - on the 1st token, expected: '6', found: '7' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '3442' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | 3rd lines differ - on the 1st token, expected: '6', found: '7' |
3 | Halted | 0 ms | 0 KB | - |