Submission #337666

# Submission time Handle Problem Language Result Execution time Memory
337666 2020-12-21T11:29:53 Z pit4h Ancient Books (IOI17_books) C++14
50 / 100
146 ms 34540 KB
#include "books.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll solve(vector<int> p, bool force) {
	int n = p.size(), s = 0, t = n-1;

	while(!force && p[s]==s) s++;
	while(p[t]==t) t--;

	ll ans = 0;

	vector<int> cnt(n), L(n), R(n);
	for(int i=s; i<=t; ++i) {
		if(p[i] > i) cnt[i]++, cnt[p[i]]--;
	}
	int delta = 0;
	for(int i=s; i<=t; ++i) {
		delta += cnt[i];
		L[i] = delta;
	}

	cnt = vector<int>(n, 0);
	for(int i=s; i<=t; ++i) {
		if(p[i] < i) {
			cnt[i-1]++;
			if(p[i]-1>=0) cnt[p[i]-1]--;
		}
	}
	delta = 0;
	for(int i=t; i>=s; --i) {
		delta += cnt[i];
		R[i] = delta;
	}
	
	for(int i=s; i<t; ++i) {
		ans += max(2, max(L[i], R[i])*2);
	}
	return ans;
}
ll minimum_walk(vector<int> p, int s) {
	int n = p.size();
	if(s==0 || p[s]!=s) {
		return solve(p, (s==0));
	}
	ll ans = 1e18+1;
	vector<int> q = p;
	for(int i=0; i<n; ++i) {
		if(i==s) continue;
		q[i] = s;
		q[s] = p[i];
		ans = min(ans, solve(q, 0));
		q[i] = p[i];
		q[s] = p[s];
	}
	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 364 KB Output is correct
4 Correct 1 ms 364 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 364 KB Output is correct
4 Correct 1 ms 364 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 384 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 364 KB Output is correct
4 Correct 1 ms 364 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 384 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 146 ms 34412 KB Output is correct
31 Correct 144 ms 34540 KB Output is correct
32 Correct 129 ms 34540 KB Output is correct
33 Correct 138 ms 34412 KB Output is correct
34 Correct 138 ms 34412 KB Output is correct
35 Correct 143 ms 34476 KB Output is correct
36 Correct 142 ms 34412 KB Output is correct
37 Correct 144 ms 34412 KB Output is correct
38 Correct 143 ms 34412 KB Output is correct
39 Correct 145 ms 34412 KB Output is correct
40 Correct 140 ms 34412 KB Output is correct
41 Correct 142 ms 34500 KB Output is correct
42 Correct 143 ms 34412 KB Output is correct
43 Correct 138 ms 34412 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: '2744'
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 364 KB Output is correct
4 Correct 1 ms 364 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 384 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 146 ms 34412 KB Output is correct
31 Correct 144 ms 34540 KB Output is correct
32 Correct 129 ms 34540 KB Output is correct
33 Correct 138 ms 34412 KB Output is correct
34 Correct 138 ms 34412 KB Output is correct
35 Correct 143 ms 34476 KB Output is correct
36 Correct 142 ms 34412 KB Output is correct
37 Correct 144 ms 34412 KB Output is correct
38 Correct 143 ms 34412 KB Output is correct
39 Correct 145 ms 34412 KB Output is correct
40 Correct 140 ms 34412 KB Output is correct
41 Correct 142 ms 34500 KB Output is correct
42 Correct 143 ms 34412 KB Output is correct
43 Correct 138 ms 34412 KB Output is correct
44 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -