Submission #338072

# Submission time Handle Problem Language Result Execution time Memory
338072 2020-12-22T12:17:04 Z cki86201 Ancient Books (IOI17_books) C++17
50 / 100
275 ms 22872 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

int c[1000010];
ll minimum_walk(vector<int> p, int s) {
	int n = szz(p);
	int l = s, r = s;
	ll ans = 0;
	rep(i, n) ans += abs(i - p[i]);
	auto expend = [&]() {
		for(int x=1;r+x<n || l-x>=0; x++) {
			if(l-x >= 0 && p[l-x] != l-x) return -x;
			if(r+x < n && p[r+x] != r+x) return x;
		}
		return 0;
	};
	vector <int> q; q.pb(s);
	auto push = [&](int x) {
		if(l > x) {
			for(int a=l-1;a>=x;a--) q.pb(a);
			l = x;
		}
		if(r < x) {
			for(int a=r+1;a<=x;a++) q.pb(a);
			r = x;
		}
	};
	while(1) {
		rep(i, szz(q)) {
			int t = q[i];
			if(c[t]) continue;
			c[t] = 1;
			for(int x=p[t];x!=t;x=p[x]) {
				push(x);
				c[x] = 1;
			}
		}
		int d = expend();
		if(d == 0) break;
		q.clear();
		ans += 2 * abs(d);
		if(d < 0) push(l + d);
		else push(r + d);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 213 ms 22872 KB Output is correct
31 Correct 275 ms 22872 KB Output is correct
32 Correct 124 ms 14828 KB Output is correct
33 Correct 146 ms 18796 KB Output is correct
34 Correct 141 ms 18796 KB Output is correct
35 Correct 147 ms 18796 KB Output is correct
36 Correct 144 ms 18796 KB Output is correct
37 Correct 139 ms 18796 KB Output is correct
38 Correct 142 ms 18924 KB Output is correct
39 Correct 141 ms 18924 KB Output is correct
40 Correct 148 ms 19048 KB Output is correct
41 Correct 165 ms 20904 KB Output is correct
42 Correct 158 ms 20444 KB Output is correct
43 Correct 147 ms 22816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 213 ms 22872 KB Output is correct
31 Correct 275 ms 22872 KB Output is correct
32 Correct 124 ms 14828 KB Output is correct
33 Correct 146 ms 18796 KB Output is correct
34 Correct 141 ms 18796 KB Output is correct
35 Correct 147 ms 18796 KB Output is correct
36 Correct 144 ms 18796 KB Output is correct
37 Correct 139 ms 18796 KB Output is correct
38 Correct 142 ms 18924 KB Output is correct
39 Correct 141 ms 18924 KB Output is correct
40 Correct 148 ms 19048 KB Output is correct
41 Correct 165 ms 20904 KB Output is correct
42 Correct 158 ms 20444 KB Output is correct
43 Correct 147 ms 22816 KB Output is correct
44 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
45 Halted 0 ms 0 KB -