# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72801 | 2018-08-27T01:57:46 Z | funcsr | Ancient Books (IOI17_books) | C++17 | 289 ms | 47716 KB |
#include "books.h" #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <cassert> using namespace std; #define rep(i,n)for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define _1 first #define _2 second #define INF 1145141919 typedef pair<int, int> P; int N; bool used[1000000]; int T[1000000]; vector<int> G[1000000]; long long minimum_walk(vector<int> A, int S) { N = A.size(); int lmin = 0, rmin = 0; rep(i, N) if (!used[i]) { if (i == A[i]) continue; int x = i; while (!used[x]) { if (x < A[x]) { T[x]++; T[A[x]]--; } used[x] = true; x = A[x]; } } rep(i,N-1) T[i+1] += T[i]; assert(S==0); long long cost = 0; bool yes = false; for (int i=N-1; i>=0; i--) { if (T[i])yes=true; cost += max(T[i], (int)yes); } return 2LL*cost; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23928 KB | Output is correct |
2 | Correct | 22 ms | 23928 KB | Output is correct |
3 | Correct | 21 ms | 23928 KB | Output is correct |
4 | Correct | 20 ms | 23928 KB | Output is correct |
5 | Correct | 23 ms | 23928 KB | Output is correct |
6 | Correct | 21 ms | 23992 KB | Output is correct |
7 | Correct | 22 ms | 23992 KB | Output is correct |
8 | Correct | 21 ms | 23992 KB | Output is correct |
9 | Correct | 22 ms | 23992 KB | Output is correct |
10 | Correct | 20 ms | 23992 KB | Output is correct |
11 | Correct | 22 ms | 23992 KB | Output is correct |
12 | Correct | 21 ms | 23992 KB | Output is correct |
13 | Correct | 21 ms | 24036 KB | Output is correct |
14 | Correct | 24 ms | 24036 KB | Output is correct |
15 | Correct | 22 ms | 24036 KB | Output is correct |
16 | Correct | 20 ms | 24036 KB | Output is correct |
17 | Correct | 21 ms | 24036 KB | Output is correct |
18 | Correct | 22 ms | 24036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23928 KB | Output is correct |
2 | Correct | 22 ms | 23928 KB | Output is correct |
3 | Correct | 21 ms | 23928 KB | Output is correct |
4 | Correct | 20 ms | 23928 KB | Output is correct |
5 | Correct | 23 ms | 23928 KB | Output is correct |
6 | Correct | 21 ms | 23992 KB | Output is correct |
7 | Correct | 22 ms | 23992 KB | Output is correct |
8 | Correct | 21 ms | 23992 KB | Output is correct |
9 | Correct | 22 ms | 23992 KB | Output is correct |
10 | Correct | 20 ms | 23992 KB | Output is correct |
11 | Correct | 22 ms | 23992 KB | Output is correct |
12 | Correct | 21 ms | 23992 KB | Output is correct |
13 | Correct | 21 ms | 24036 KB | Output is correct |
14 | Correct | 24 ms | 24036 KB | Output is correct |
15 | Correct | 22 ms | 24036 KB | Output is correct |
16 | Correct | 20 ms | 24036 KB | Output is correct |
17 | Correct | 21 ms | 24036 KB | Output is correct |
18 | Correct | 22 ms | 24036 KB | Output is correct |
19 | Correct | 23 ms | 24036 KB | Output is correct |
20 | Correct | 21 ms | 24036 KB | Output is correct |
21 | Correct | 23 ms | 24036 KB | Output is correct |
22 | Correct | 26 ms | 24036 KB | Output is correct |
23 | Correct | 22 ms | 24036 KB | Output is correct |
24 | Correct | 21 ms | 24036 KB | Output is correct |
25 | Correct | 22 ms | 24080 KB | Output is correct |
26 | Correct | 23 ms | 24080 KB | Output is correct |
27 | Correct | 22 ms | 24084 KB | Output is correct |
28 | Correct | 23 ms | 24084 KB | Output is correct |
29 | Correct | 21 ms | 24084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23928 KB | Output is correct |
2 | Correct | 22 ms | 23928 KB | Output is correct |
3 | Correct | 21 ms | 23928 KB | Output is correct |
4 | Correct | 20 ms | 23928 KB | Output is correct |
5 | Correct | 23 ms | 23928 KB | Output is correct |
6 | Correct | 21 ms | 23992 KB | Output is correct |
7 | Correct | 22 ms | 23992 KB | Output is correct |
8 | Correct | 21 ms | 23992 KB | Output is correct |
9 | Correct | 22 ms | 23992 KB | Output is correct |
10 | Correct | 20 ms | 23992 KB | Output is correct |
11 | Correct | 22 ms | 23992 KB | Output is correct |
12 | Correct | 21 ms | 23992 KB | Output is correct |
13 | Correct | 21 ms | 24036 KB | Output is correct |
14 | Correct | 24 ms | 24036 KB | Output is correct |
15 | Correct | 22 ms | 24036 KB | Output is correct |
16 | Correct | 20 ms | 24036 KB | Output is correct |
17 | Correct | 21 ms | 24036 KB | Output is correct |
18 | Correct | 22 ms | 24036 KB | Output is correct |
19 | Correct | 23 ms | 24036 KB | Output is correct |
20 | Correct | 21 ms | 24036 KB | Output is correct |
21 | Correct | 23 ms | 24036 KB | Output is correct |
22 | Correct | 26 ms | 24036 KB | Output is correct |
23 | Correct | 22 ms | 24036 KB | Output is correct |
24 | Correct | 21 ms | 24036 KB | Output is correct |
25 | Correct | 22 ms | 24080 KB | Output is correct |
26 | Correct | 23 ms | 24080 KB | Output is correct |
27 | Correct | 22 ms | 24084 KB | Output is correct |
28 | Correct | 23 ms | 24084 KB | Output is correct |
29 | Correct | 21 ms | 24084 KB | Output is correct |
30 | Correct | 289 ms | 36836 KB | Output is correct |
31 | Correct | 277 ms | 36836 KB | Output is correct |
32 | Correct | 166 ms | 36836 KB | Output is correct |
33 | Correct | 177 ms | 36836 KB | Output is correct |
34 | Correct | 176 ms | 36836 KB | Output is correct |
35 | Correct | 181 ms | 36836 KB | Output is correct |
36 | Correct | 182 ms | 36836 KB | Output is correct |
37 | Correct | 182 ms | 36836 KB | Output is correct |
38 | Correct | 180 ms | 36836 KB | Output is correct |
39 | Correct | 201 ms | 36836 KB | Output is correct |
40 | Correct | 199 ms | 36836 KB | Output is correct |
41 | Correct | 228 ms | 36852 KB | Output is correct |
42 | Correct | 223 ms | 36852 KB | Output is correct |
43 | Correct | 207 ms | 36852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 41 ms | 47716 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23928 KB | Output is correct |
2 | Correct | 22 ms | 23928 KB | Output is correct |
3 | Correct | 21 ms | 23928 KB | Output is correct |
4 | Correct | 20 ms | 23928 KB | Output is correct |
5 | Correct | 23 ms | 23928 KB | Output is correct |
6 | Correct | 21 ms | 23992 KB | Output is correct |
7 | Correct | 22 ms | 23992 KB | Output is correct |
8 | Correct | 21 ms | 23992 KB | Output is correct |
9 | Correct | 22 ms | 23992 KB | Output is correct |
10 | Correct | 20 ms | 23992 KB | Output is correct |
11 | Correct | 22 ms | 23992 KB | Output is correct |
12 | Correct | 21 ms | 23992 KB | Output is correct |
13 | Correct | 21 ms | 24036 KB | Output is correct |
14 | Correct | 24 ms | 24036 KB | Output is correct |
15 | Correct | 22 ms | 24036 KB | Output is correct |
16 | Correct | 20 ms | 24036 KB | Output is correct |
17 | Correct | 21 ms | 24036 KB | Output is correct |
18 | Correct | 22 ms | 24036 KB | Output is correct |
19 | Correct | 23 ms | 24036 KB | Output is correct |
20 | Correct | 21 ms | 24036 KB | Output is correct |
21 | Correct | 23 ms | 24036 KB | Output is correct |
22 | Correct | 26 ms | 24036 KB | Output is correct |
23 | Correct | 22 ms | 24036 KB | Output is correct |
24 | Correct | 21 ms | 24036 KB | Output is correct |
25 | Correct | 22 ms | 24080 KB | Output is correct |
26 | Correct | 23 ms | 24080 KB | Output is correct |
27 | Correct | 22 ms | 24084 KB | Output is correct |
28 | Correct | 23 ms | 24084 KB | Output is correct |
29 | Correct | 21 ms | 24084 KB | Output is correct |
30 | Correct | 289 ms | 36836 KB | Output is correct |
31 | Correct | 277 ms | 36836 KB | Output is correct |
32 | Correct | 166 ms | 36836 KB | Output is correct |
33 | Correct | 177 ms | 36836 KB | Output is correct |
34 | Correct | 176 ms | 36836 KB | Output is correct |
35 | Correct | 181 ms | 36836 KB | Output is correct |
36 | Correct | 182 ms | 36836 KB | Output is correct |
37 | Correct | 182 ms | 36836 KB | Output is correct |
38 | Correct | 180 ms | 36836 KB | Output is correct |
39 | Correct | 201 ms | 36836 KB | Output is correct |
40 | Correct | 199 ms | 36836 KB | Output is correct |
41 | Correct | 228 ms | 36852 KB | Output is correct |
42 | Correct | 223 ms | 36852 KB | Output is correct |
43 | Correct | 207 ms | 36852 KB | Output is correct |
44 | Runtime error | 41 ms | 47716 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
45 | Halted | 0 ms | 0 KB | - |