# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
239074 |
2020-06-14T10:04:35 Z |
lyc |
Ancient Books (IOI17_books) |
C++14 |
|
241 ms |
22904 KB |
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cout << #x << " :: " << x << endl;
#define _ << " " <<
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
const int mxN = 1e6+5;
int N, L, R;
int go[mxN][2];
void ext(int& l, int& r) {
int x = l, y = r;
do {
FOR(j,0,1){
if (l >= L && go[l][j] != -1) x = min(x,go[l][j]), y = max(y,go[l][j]);
if (r < R && go[r][j] != -1) x = min(x,go[r][j]), y = max(y,go[r][j]);
}
if (x < l) --l;
if (r < y) ++r;
} while (x < l || r < y);
}
long long minimum_walk(std::vector<int> p, int s) {
N = SZ(p);
long long lb = 0;
L = N-1, R = 0;
memset(go,-1,sizeof go);
FOR(i,0,N-1){
if (i != p[i]) {
lb += abs(p[i]-i);
L = min({L,i,p[i]}), R = max({R,i,p[i]});
FOR(j,0,1) if (go[i][j] == -1) { go[i][j] = p[i]; break; }
FOR(j,0,1) if (go[p[i]][j] == -1) { go[p[i]][j] = i; break; }
}
}
long long add = 0;
int l = s, r = s;
for (;;) {
ext(l,r);
if (l <= L && r >= R) break;
add += 2;
--l, ++r;
}
//TRACE(lb _ add);
return lb + add;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
10 ms |
8192 KB |
Output is correct |
6 |
Correct |
8 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
8 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8192 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
10 ms |
8192 KB |
Output is correct |
6 |
Correct |
8 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
8 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8192 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
10 ms |
8192 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8192 KB |
Output is correct |
22 |
Correct |
10 ms |
8192 KB |
Output is correct |
23 |
Correct |
8 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
9 ms |
8192 KB |
Output is correct |
27 |
Correct |
8 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
10 ms |
8192 KB |
Output is correct |
6 |
Correct |
8 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
8 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8192 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
10 ms |
8192 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8192 KB |
Output is correct |
22 |
Correct |
10 ms |
8192 KB |
Output is correct |
23 |
Correct |
8 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
9 ms |
8192 KB |
Output is correct |
27 |
Correct |
8 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
9 ms |
8192 KB |
Output is correct |
30 |
Correct |
241 ms |
22648 KB |
Output is correct |
31 |
Correct |
215 ms |
22776 KB |
Output is correct |
32 |
Correct |
159 ms |
22648 KB |
Output is correct |
33 |
Correct |
175 ms |
22652 KB |
Output is correct |
34 |
Correct |
182 ms |
22904 KB |
Output is correct |
35 |
Correct |
183 ms |
22776 KB |
Output is correct |
36 |
Correct |
173 ms |
22648 KB |
Output is correct |
37 |
Correct |
177 ms |
22648 KB |
Output is correct |
38 |
Correct |
196 ms |
22648 KB |
Output is correct |
39 |
Correct |
191 ms |
22752 KB |
Output is correct |
40 |
Correct |
188 ms |
22860 KB |
Output is correct |
41 |
Correct |
202 ms |
22780 KB |
Output is correct |
42 |
Correct |
204 ms |
22732 KB |
Output is correct |
43 |
Correct |
178 ms |
22776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
2 |
Correct |
10 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Incorrect |
10 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '2094', found: '1592' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
10 ms |
8192 KB |
Output is correct |
6 |
Correct |
8 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
8 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8192 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
10 ms |
8192 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8192 KB |
Output is correct |
22 |
Correct |
10 ms |
8192 KB |
Output is correct |
23 |
Correct |
8 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
9 ms |
8192 KB |
Output is correct |
27 |
Correct |
8 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
9 ms |
8192 KB |
Output is correct |
30 |
Correct |
241 ms |
22648 KB |
Output is correct |
31 |
Correct |
215 ms |
22776 KB |
Output is correct |
32 |
Correct |
159 ms |
22648 KB |
Output is correct |
33 |
Correct |
175 ms |
22652 KB |
Output is correct |
34 |
Correct |
182 ms |
22904 KB |
Output is correct |
35 |
Correct |
183 ms |
22776 KB |
Output is correct |
36 |
Correct |
173 ms |
22648 KB |
Output is correct |
37 |
Correct |
177 ms |
22648 KB |
Output is correct |
38 |
Correct |
196 ms |
22648 KB |
Output is correct |
39 |
Correct |
191 ms |
22752 KB |
Output is correct |
40 |
Correct |
188 ms |
22860 KB |
Output is correct |
41 |
Correct |
202 ms |
22780 KB |
Output is correct |
42 |
Correct |
204 ms |
22732 KB |
Output is correct |
43 |
Correct |
178 ms |
22776 KB |
Output is correct |
44 |
Correct |
9 ms |
8192 KB |
Output is correct |
45 |
Correct |
10 ms |
8192 KB |
Output is correct |
46 |
Correct |
9 ms |
8192 KB |
Output is correct |
47 |
Incorrect |
10 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '2094', found: '1592' |
48 |
Halted |
0 ms |
0 KB |
- |