답안 #408316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408316 2021-05-19T06:56:40 Z Kevin_Zhang_TW 고대 책들 (IOI17_books) C++17
50 / 100
192 ms 22668 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 300010;

#include "books.h"

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	vector<int> cntl(n+1), cntr(n+1);

	for (int i = 0;i < n;++i) {
		if (p[i] < i) 
			++cntl[p[i]+1], --cntl[i+1];
		if (p[i] > i)
			++cntr[i], --cntr[p[i]];
	}
	if (is_sorted(AI(p))) return 0;

	ll res = 0;

	for (int i = 1;i <= n;++i) {
		cntr[i] += cntr[i-1];
		cntl[i] += cntl[i-1];
	}

	int l = 0, r = n-1;
	while (p[l] == l) ++l;
	while (p[r] == r) --r;

	for (int i = l;i < r;++i) {
		res += max({cntl[i+1], cntr[i], 1}) * 2;
	}
//
	if (s > r) res += (s - r) * 2;
	if (s < l) res += (l - s) * 2;
	if (s <= r && s >= l) {
		int L = s, R = s;
		while (cntl[L]) --L;
		while (cntr[R]) ++R;
		int mn = s-l;

		int g = s;
		while (p[g] == g) ++g;
		chmin(mn, g - s);
		g = s;
		while (p[g] == g) --g;
		chmin(mn, s - g);

		res += mn * 2;
	}

	return res;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 154 ms 22608 KB Output is correct
31 Correct 191 ms 22612 KB Output is correct
32 Correct 161 ms 22612 KB Output is correct
33 Correct 146 ms 22624 KB Output is correct
34 Correct 160 ms 22604 KB Output is correct
35 Correct 147 ms 22612 KB Output is correct
36 Correct 152 ms 22612 KB Output is correct
37 Correct 192 ms 22612 KB Output is correct
38 Correct 169 ms 22668 KB Output is correct
39 Correct 184 ms 22616 KB Output is correct
40 Correct 181 ms 22632 KB Output is correct
41 Correct 180 ms 22624 KB Output is correct
42 Correct 176 ms 22616 KB Output is correct
43 Correct 162 ms 22616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 216 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 154 ms 22608 KB Output is correct
31 Correct 191 ms 22612 KB Output is correct
32 Correct 161 ms 22612 KB Output is correct
33 Correct 146 ms 22624 KB Output is correct
34 Correct 160 ms 22604 KB Output is correct
35 Correct 147 ms 22612 KB Output is correct
36 Correct 152 ms 22612 KB Output is correct
37 Correct 192 ms 22612 KB Output is correct
38 Correct 169 ms 22668 KB Output is correct
39 Correct 184 ms 22616 KB Output is correct
40 Correct 181 ms 22632 KB Output is correct
41 Correct 180 ms 22624 KB Output is correct
42 Correct 176 ms 22616 KB Output is correct
43 Correct 162 ms 22616 KB Output is correct
44 Incorrect 2 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -