답안 #337674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337674 2020-12-21T11:35:49 Z pit4h 고대 책들 (IOI17_books) C++14
50 / 100
164 ms 32236 KB
#include "books.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll solve(vector<int> p, int force) {
	int n = p.size(), s = 0, t = n-1;

	while(s+1<=force && p[s]==s) s++;
	while(t-1>=force && 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();
	vector<int> pref(n);
	pref[0] = p[0];
	for(int i=1; i<n; ++i) {
		pref[i] = max(pref[i-1], p[i]);
	}
	if(s==0 || p[s]!=s || pref[s-1]<s) {
		return solve(p, s);
	}
	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, s));
		q[i] = p[i];
		q[s] = p[s];
	}
	return ans;
}
# 결과 실행 시간 메모리 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 492 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 384 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
# 결과 실행 시간 메모리 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 492 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 384 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
# 결과 실행 시간 메모리 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 492 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 384 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 153 ms 32108 KB Output is correct
31 Correct 150 ms 32236 KB Output is correct
32 Correct 133 ms 32108 KB Output is correct
33 Correct 142 ms 32236 KB Output is correct
34 Correct 140 ms 32108 KB Output is correct
35 Correct 141 ms 32108 KB Output is correct
36 Correct 148 ms 32108 KB Output is correct
37 Correct 164 ms 32108 KB Output is correct
38 Correct 150 ms 32188 KB Output is correct
39 Correct 152 ms 32236 KB Output is correct
40 Correct 149 ms 32108 KB Output is correct
41 Correct 155 ms 32108 KB Output is correct
42 Correct 150 ms 32220 KB Output is correct
43 Correct 149 ms 32108 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 492 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 384 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 153 ms 32108 KB Output is correct
31 Correct 150 ms 32236 KB Output is correct
32 Correct 133 ms 32108 KB Output is correct
33 Correct 142 ms 32236 KB Output is correct
34 Correct 140 ms 32108 KB Output is correct
35 Correct 141 ms 32108 KB Output is correct
36 Correct 148 ms 32108 KB Output is correct
37 Correct 164 ms 32108 KB Output is correct
38 Correct 150 ms 32188 KB Output is correct
39 Correct 152 ms 32236 KB Output is correct
40 Correct 149 ms 32108 KB Output is correct
41 Correct 155 ms 32108 KB Output is correct
42 Correct 150 ms 32220 KB Output is correct
43 Correct 149 ms 32108 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 -