Submission #58917

# Submission time Handle Problem Language Result Execution time Memory
58917 2018-07-19T19:55:34 Z reality Ancient Books (IOI17_books) C++17
50 / 100
451 ms 165768 KB
#include "books.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
#include "books.h"
const int oo = 1e9;
int n;
int D1[20][1 << 20];
int D2[20][1 << 20];
int Log[1 << 20];
int get1(int l,int r) {
	int k = Log[r - l + 1];
	return min(D1[k][l],D1[k][r - (1 << k) + 1]);
}
int get2(int l,int r) {
	int k = Log[r - l + 1];
	return max(D2[k][l],D2[k][r - (1 << k) + 1]);
}
long long minimum_walk(std::vector<int> p, int s) {
	n = p.size();
	int a = 0,b = n - 1;
	while (a + 1 <= s && p[a] == a)
		--a;
	while (b - 1 >= s && p[b] == b)
		--b;
	int l = s,r = s;
	ll ans = 0;
	for (int i = 0;i < n;++i)
		ans += abs(i - p[i]);
	for (int i = 0;i < n;++i) {
		D1[0][i] = D2[0][i] = p[i];
	}
	for (int t = 1;t < 20;++t)
		for (int i = 0;i + (1 << t) <= n;++i) {
			D1[t][i] = min(D1[t - 1][i],D1[t - 1][i + (1 << (t - 1))]);
			D2[t][i] = max(D2[t - 1][i],D2[t - 1][i + (1 << (t - 1))]);
		}
	for (int i = 2;i <= n;++i)
		Log[i] = Log[i / 2] + 1;
	while (a < l || r < b) {
		while (get1(l,r) < l || r < get2(l,r)) {
			smin(l,get1(l,r));
			smax(r,get2(l,r));
		}
		if (l - 1 >= a) {
			--l;
			ans += 2;
		} 
		if (r + 1 <= b) {
			++r;
			ans += 2;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 532 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 532 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 948 KB Output is correct
24 Correct 3 ms 948 KB Output is correct
25 Correct 3 ms 948 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 3 ms 948 KB Output is correct
28 Correct 4 ms 948 KB Output is correct
29 Correct 3 ms 948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 532 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 948 KB Output is correct
24 Correct 3 ms 948 KB Output is correct
25 Correct 3 ms 948 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 3 ms 948 KB Output is correct
28 Correct 4 ms 948 KB Output is correct
29 Correct 3 ms 948 KB Output is correct
30 Correct 342 ms 165440 KB Output is correct
31 Correct 451 ms 165440 KB Output is correct
32 Correct 288 ms 165440 KB Output is correct
33 Correct 277 ms 165440 KB Output is correct
34 Correct 340 ms 165440 KB Output is correct
35 Correct 321 ms 165440 KB Output is correct
36 Correct 343 ms 165448 KB Output is correct
37 Correct 315 ms 165448 KB Output is correct
38 Correct 363 ms 165448 KB Output is correct
39 Correct 329 ms 165448 KB Output is correct
40 Correct 321 ms 165704 KB Output is correct
41 Correct 327 ms 165720 KB Output is correct
42 Correct 314 ms 165720 KB Output is correct
43 Correct 308 ms 165768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 165768 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3864'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 532 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 2 ms 892 KB Output is correct
23 Correct 3 ms 948 KB Output is correct
24 Correct 3 ms 948 KB Output is correct
25 Correct 3 ms 948 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 3 ms 948 KB Output is correct
28 Correct 4 ms 948 KB Output is correct
29 Correct 3 ms 948 KB Output is correct
30 Correct 342 ms 165440 KB Output is correct
31 Correct 451 ms 165440 KB Output is correct
32 Correct 288 ms 165440 KB Output is correct
33 Correct 277 ms 165440 KB Output is correct
34 Correct 340 ms 165440 KB Output is correct
35 Correct 321 ms 165440 KB Output is correct
36 Correct 343 ms 165448 KB Output is correct
37 Correct 315 ms 165448 KB Output is correct
38 Correct 363 ms 165448 KB Output is correct
39 Correct 329 ms 165448 KB Output is correct
40 Correct 321 ms 165704 KB Output is correct
41 Correct 327 ms 165720 KB Output is correct
42 Correct 314 ms 165720 KB Output is correct
43 Correct 308 ms 165768 KB Output is correct
44 Incorrect 2 ms 165768 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3864'
45 Halted 0 ms 0 KB -