# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341004 | 2020-12-28T21:08:27 Z | pggp | Ancient Books (IOI17_books) | C++14 | 260 ms | 94568 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; long long ans = 0; void dfs(int vertex){ cycle[vertex] = cur_cycle; cycs[cur_cycle].push_back(vertex); used[vertex] = true; ans += abs(vertex - P[vertex]); if(!used[P[vertex]]){ dfs(P[vertex]); } } long long minimum_walk(vector < int > p, int s){ cur_cycle = 0; for (int i = 0; i < 1000000; ++i) { used[i] = false; cycle[i] = 0; } cycs.clear(); l_cyc.clear(); r_cyc.clear(); 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) { //if(cycs[i].size() == 1) continue; 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()); int components = 1; int max_r = f[0].second; int last_comp = 0; for (int i = 1; i < f.size(); ++i) { //cout << f[i].first << " " << f[i].second << endl; if(f[i].first > max_r){ components++; if(f[i].first == f[i].second){ last_comp++; } else{ last_comp = 0; } } max_r = max(max_r, f[i].second); } components -= last_comp; ans += 2 * components - 2; //cout << components << endl; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5228 KB | Output is correct |
2 | Correct | 4 ms | 5228 KB | Output is correct |
3 | Correct | 4 ms | 5228 KB | Output is correct |
4 | Correct | 4 ms | 5228 KB | Output is correct |
5 | Correct | 4 ms | 5228 KB | Output is correct |
6 | Correct | 5 ms | 5228 KB | Output is correct |
7 | Correct | 4 ms | 5228 KB | Output is correct |
8 | Correct | 5 ms | 5228 KB | Output is correct |
9 | Correct | 4 ms | 5228 KB | Output is correct |
10 | Correct | 4 ms | 5228 KB | Output is correct |
11 | Correct | 4 ms | 5228 KB | Output is correct |
12 | Correct | 4 ms | 5228 KB | Output is correct |
13 | Correct | 4 ms | 5228 KB | Output is correct |
14 | Correct | 4 ms | 5228 KB | Output is correct |
15 | Correct | 5 ms | 5228 KB | Output is correct |
16 | Correct | 5 ms | 5228 KB | Output is correct |
17 | Correct | 5 ms | 5228 KB | Output is correct |
18 | Correct | 4 ms | 5228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5228 KB | Output is correct |
2 | Correct | 4 ms | 5228 KB | Output is correct |
3 | Correct | 4 ms | 5228 KB | Output is correct |
4 | Correct | 4 ms | 5228 KB | Output is correct |
5 | Correct | 4 ms | 5228 KB | Output is correct |
6 | Correct | 5 ms | 5228 KB | Output is correct |
7 | Correct | 4 ms | 5228 KB | Output is correct |
8 | Correct | 5 ms | 5228 KB | Output is correct |
9 | Correct | 4 ms | 5228 KB | Output is correct |
10 | Correct | 4 ms | 5228 KB | Output is correct |
11 | Correct | 4 ms | 5228 KB | Output is correct |
12 | Correct | 4 ms | 5228 KB | Output is correct |
13 | Correct | 4 ms | 5228 KB | Output is correct |
14 | Correct | 4 ms | 5228 KB | Output is correct |
15 | Correct | 5 ms | 5228 KB | Output is correct |
16 | Correct | 5 ms | 5228 KB | Output is correct |
17 | Correct | 5 ms | 5228 KB | Output is correct |
18 | Correct | 4 ms | 5228 KB | Output is correct |
19 | Correct | 5 ms | 5248 KB | Output is correct |
20 | Correct | 4 ms | 5228 KB | Output is correct |
21 | Correct | 5 ms | 5228 KB | Output is correct |
22 | Correct | 5 ms | 5228 KB | Output is correct |
23 | Correct | 5 ms | 5228 KB | Output is correct |
24 | Correct | 5 ms | 5228 KB | Output is correct |
25 | Correct | 5 ms | 5228 KB | Output is correct |
26 | Correct | 5 ms | 5228 KB | Output is correct |
27 | Correct | 5 ms | 5228 KB | Output is correct |
28 | Correct | 5 ms | 5228 KB | Output is correct |
29 | Correct | 6 ms | 5228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5228 KB | Output is correct |
2 | Correct | 4 ms | 5228 KB | Output is correct |
3 | Correct | 4 ms | 5228 KB | Output is correct |
4 | Correct | 4 ms | 5228 KB | Output is correct |
5 | Correct | 4 ms | 5228 KB | Output is correct |
6 | Correct | 5 ms | 5228 KB | Output is correct |
7 | Correct | 4 ms | 5228 KB | Output is correct |
8 | Correct | 5 ms | 5228 KB | Output is correct |
9 | Correct | 4 ms | 5228 KB | Output is correct |
10 | Correct | 4 ms | 5228 KB | Output is correct |
11 | Correct | 4 ms | 5228 KB | Output is correct |
12 | Correct | 4 ms | 5228 KB | Output is correct |
13 | Correct | 4 ms | 5228 KB | Output is correct |
14 | Correct | 4 ms | 5228 KB | Output is correct |
15 | Correct | 5 ms | 5228 KB | Output is correct |
16 | Correct | 5 ms | 5228 KB | Output is correct |
17 | Correct | 5 ms | 5228 KB | Output is correct |
18 | Correct | 4 ms | 5228 KB | Output is correct |
19 | Correct | 5 ms | 5248 KB | Output is correct |
20 | Correct | 4 ms | 5228 KB | Output is correct |
21 | Correct | 5 ms | 5228 KB | Output is correct |
22 | Correct | 5 ms | 5228 KB | Output is correct |
23 | Correct | 5 ms | 5228 KB | Output is correct |
24 | Correct | 5 ms | 5228 KB | Output is correct |
25 | Correct | 5 ms | 5228 KB | Output is correct |
26 | Correct | 5 ms | 5228 KB | Output is correct |
27 | Correct | 5 ms | 5228 KB | Output is correct |
28 | Correct | 5 ms | 5228 KB | Output is correct |
29 | Correct | 6 ms | 5228 KB | Output is correct |
30 | Correct | 252 ms | 52948 KB | Output is correct |
31 | Correct | 244 ms | 41132 KB | Output is correct |
32 | Correct | 260 ms | 94568 KB | Output is correct |
33 | Correct | 250 ms | 75368 KB | Output is correct |
34 | Correct | 255 ms | 75368 KB | Output is correct |
35 | Correct | 242 ms | 66944 KB | Output is correct |
36 | Correct | 201 ms | 44436 KB | Output is correct |
37 | Correct | 165 ms | 31520 KB | Output is correct |
38 | Correct | 160 ms | 29804 KB | Output is correct |
39 | Correct | 160 ms | 29804 KB | Output is correct |
40 | Correct | 164 ms | 29672 KB | Output is correct |
41 | Correct | 190 ms | 38780 KB | Output is correct |
42 | Correct | 176 ms | 33124 KB | Output is correct |
43 | Correct | 252 ms | 78312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 5228 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 | 5 ms | 5228 KB | Output is correct |
2 | Correct | 4 ms | 5228 KB | Output is correct |
3 | Correct | 4 ms | 5228 KB | Output is correct |
4 | Correct | 4 ms | 5228 KB | Output is correct |
5 | Correct | 4 ms | 5228 KB | Output is correct |
6 | Correct | 5 ms | 5228 KB | Output is correct |
7 | Correct | 4 ms | 5228 KB | Output is correct |
8 | Correct | 5 ms | 5228 KB | Output is correct |
9 | Correct | 4 ms | 5228 KB | Output is correct |
10 | Correct | 4 ms | 5228 KB | Output is correct |
11 | Correct | 4 ms | 5228 KB | Output is correct |
12 | Correct | 4 ms | 5228 KB | Output is correct |
13 | Correct | 4 ms | 5228 KB | Output is correct |
14 | Correct | 4 ms | 5228 KB | Output is correct |
15 | Correct | 5 ms | 5228 KB | Output is correct |
16 | Correct | 5 ms | 5228 KB | Output is correct |
17 | Correct | 5 ms | 5228 KB | Output is correct |
18 | Correct | 4 ms | 5228 KB | Output is correct |
19 | Correct | 5 ms | 5248 KB | Output is correct |
20 | Correct | 4 ms | 5228 KB | Output is correct |
21 | Correct | 5 ms | 5228 KB | Output is correct |
22 | Correct | 5 ms | 5228 KB | Output is correct |
23 | Correct | 5 ms | 5228 KB | Output is correct |
24 | Correct | 5 ms | 5228 KB | Output is correct |
25 | Correct | 5 ms | 5228 KB | Output is correct |
26 | Correct | 5 ms | 5228 KB | Output is correct |
27 | Correct | 5 ms | 5228 KB | Output is correct |
28 | Correct | 5 ms | 5228 KB | Output is correct |
29 | Correct | 6 ms | 5228 KB | Output is correct |
30 | Correct | 252 ms | 52948 KB | Output is correct |
31 | Correct | 244 ms | 41132 KB | Output is correct |
32 | Correct | 260 ms | 94568 KB | Output is correct |
33 | Correct | 250 ms | 75368 KB | Output is correct |
34 | Correct | 255 ms | 75368 KB | Output is correct |
35 | Correct | 242 ms | 66944 KB | Output is correct |
36 | Correct | 201 ms | 44436 KB | Output is correct |
37 | Correct | 165 ms | 31520 KB | Output is correct |
38 | Correct | 160 ms | 29804 KB | Output is correct |
39 | Correct | 160 ms | 29804 KB | Output is correct |
40 | Correct | 164 ms | 29672 KB | Output is correct |
41 | Correct | 190 ms | 38780 KB | Output is correct |
42 | Correct | 176 ms | 33124 KB | Output is correct |
43 | Correct | 252 ms | 78312 KB | Output is correct |
44 | Incorrect | 4 ms | 5228 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 | Halted | 0 ms | 0 KB | - |