# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
474087 | 2021-09-16T20:24:42 Z | AdamGS | Ancient Books (IOI17_books) | C++14 | 175 ms | 27132 KB |
#include "books.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(ll a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e6+7; int F[LIM]; int fnd(int x) { if(F[x]==x) return x; return F[x]=fnd(F[x]); } void uni(int a, int b) { if(fnd(a)>fnd(b)) { F[fnd(b)]=fnd(a); } else { F[fnd(a)]=fnd(b); } } ll minimum_walk(vector<int>p, int s) { int n=p.size(); rep(i, n) F[i]=i; vector<ll>V; for(auto i : p) V.pb(i); ll ans=0; rep(i, V.size()) { ans+=abs(i-V[i]); uni(i, V[i]); } int r=n-1; while(r && V[r]==r) --r; int l=0, aktma=fnd(0); while(l<r) { if(aktma==l) ans+=2; ++l; aktma=max(aktma, fnd(l)); } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 169 ms | 27084 KB | Output is correct |
31 | Correct | 175 ms | 27084 KB | Output is correct |
32 | Correct | 134 ms | 27096 KB | Output is correct |
33 | Correct | 138 ms | 27056 KB | Output is correct |
34 | Correct | 139 ms | 27132 KB | Output is correct |
35 | Correct | 141 ms | 27088 KB | Output is correct |
36 | Correct | 148 ms | 27000 KB | Output is correct |
37 | Correct | 147 ms | 27000 KB | Output is correct |
38 | Correct | 153 ms | 27000 KB | Output is correct |
39 | Correct | 149 ms | 27088 KB | Output is correct |
40 | Correct | 154 ms | 27104 KB | Output is correct |
41 | Correct | 165 ms | 27084 KB | Output is correct |
42 | Correct | 174 ms | 27056 KB | Output is correct |
43 | Correct | 137 ms | 27084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 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 | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 169 ms | 27084 KB | Output is correct |
31 | Correct | 175 ms | 27084 KB | Output is correct |
32 | Correct | 134 ms | 27096 KB | Output is correct |
33 | Correct | 138 ms | 27056 KB | Output is correct |
34 | Correct | 139 ms | 27132 KB | Output is correct |
35 | Correct | 141 ms | 27088 KB | Output is correct |
36 | Correct | 148 ms | 27000 KB | Output is correct |
37 | Correct | 147 ms | 27000 KB | Output is correct |
38 | Correct | 153 ms | 27000 KB | Output is correct |
39 | Correct | 149 ms | 27088 KB | Output is correct |
40 | Correct | 154 ms | 27104 KB | Output is correct |
41 | Correct | 165 ms | 27084 KB | Output is correct |
42 | Correct | 174 ms | 27056 KB | Output is correct |
43 | Correct | 137 ms | 27084 KB | Output is correct |
44 | Incorrect | 1 ms | 332 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 | Halted | 0 ms | 0 KB | - |