답안 #51836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51836 2018-06-21T14:07:20 Z aome 고대 책들 (IOI17_books) C++17
50 / 100
199 ms 106844 KB
#include <bits/stdc++.h>
#include "books.h"
 
using namespace std;
 
const int N = 1000005;
 
long long minimum_walk(vector<int> p, int s) {
	int n = p.size();
	long long res = 0;
	for (int i = 0; i < n; ++i) res += abs(i - p[i]);
	int ml = n - 1, mr = 0;
	for (int i = 0; i < n; ++i) {
		if (i != p[i]) ml = min(ml, i), mr = max(mr, i);
	}
	int cl = s, cr = s;
	queue<int> qu; qu.push(s);
	while (1) {
		while (qu.size()) {
			int u = qu.front(); qu.pop();
			while (cl > p[u]) {
				cl--, qu.push(cl);
			}
			while (cr < p[u]) {
				cr++, qu.push(cr);
			}
		}
		int l = cl, r = cr;
		int dl = 0, dr = 0;
		bool fl = 0, fr = 0;
		queue<int> ql, qr;
		while (1) {
			if (l <= ml) break;
			l--, dl++, ql.push(l);
			while (ql.size()) {
				int u = ql.front(); ql.pop();
				while (l > p[u]) {
					l--, ql.push(l);
				}
				if (p[u] > s) fl = 1;
			}
			if (fl) break; 
		}
		while (1) {
			if (r >= mr) break;
			r++, dr++, qr.push(r);
			while (qr.size()) {
				int u = qr.front(); qr.pop();
				while (r < p[u]) {
					r++, qr.push(r);
				}
				if (p[u] < s) fr = 1;
			}
			if (fr) break;
		}
		if (fl && fr) {
			cl = l, cr = r, res += 2 * min(dl, dr);
		}
		else {
			res += 2 * (dl + dr); break;
		}
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 792 KB Output is correct
20 Correct 2 ms 792 KB Output is correct
21 Correct 2 ms 792 KB Output is correct
22 Correct 2 ms 804 KB Output is correct
23 Correct 2 ms 808 KB Output is correct
24 Correct 3 ms 812 KB Output is correct
25 Correct 2 ms 812 KB Output is correct
26 Correct 2 ms 812 KB Output is correct
27 Correct 2 ms 824 KB Output is correct
28 Correct 2 ms 828 KB Output is correct
29 Correct 2 ms 832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 792 KB Output is correct
20 Correct 2 ms 792 KB Output is correct
21 Correct 2 ms 792 KB Output is correct
22 Correct 2 ms 804 KB Output is correct
23 Correct 2 ms 808 KB Output is correct
24 Correct 3 ms 812 KB Output is correct
25 Correct 2 ms 812 KB Output is correct
26 Correct 2 ms 812 KB Output is correct
27 Correct 2 ms 824 KB Output is correct
28 Correct 2 ms 828 KB Output is correct
29 Correct 2 ms 832 KB Output is correct
30 Correct 194 ms 19592 KB Output is correct
31 Correct 176 ms 26316 KB Output is correct
32 Correct 139 ms 28896 KB Output is correct
33 Correct 177 ms 35708 KB Output is correct
34 Correct 156 ms 42500 KB Output is correct
35 Correct 164 ms 49108 KB Output is correct
36 Correct 154 ms 55780 KB Output is correct
37 Correct 168 ms 62524 KB Output is correct
38 Correct 199 ms 69396 KB Output is correct
39 Correct 167 ms 76140 KB Output is correct
40 Correct 172 ms 82968 KB Output is correct
41 Correct 190 ms 91724 KB Output is correct
42 Correct 180 ms 97928 KB Output is correct
43 Correct 174 ms 106844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 106844 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3310'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 792 KB Output is correct
20 Correct 2 ms 792 KB Output is correct
21 Correct 2 ms 792 KB Output is correct
22 Correct 2 ms 804 KB Output is correct
23 Correct 2 ms 808 KB Output is correct
24 Correct 3 ms 812 KB Output is correct
25 Correct 2 ms 812 KB Output is correct
26 Correct 2 ms 812 KB Output is correct
27 Correct 2 ms 824 KB Output is correct
28 Correct 2 ms 828 KB Output is correct
29 Correct 2 ms 832 KB Output is correct
30 Correct 194 ms 19592 KB Output is correct
31 Correct 176 ms 26316 KB Output is correct
32 Correct 139 ms 28896 KB Output is correct
33 Correct 177 ms 35708 KB Output is correct
34 Correct 156 ms 42500 KB Output is correct
35 Correct 164 ms 49108 KB Output is correct
36 Correct 154 ms 55780 KB Output is correct
37 Correct 168 ms 62524 KB Output is correct
38 Correct 199 ms 69396 KB Output is correct
39 Correct 167 ms 76140 KB Output is correct
40 Correct 172 ms 82968 KB Output is correct
41 Correct 190 ms 91724 KB Output is correct
42 Correct 180 ms 97928 KB Output is correct
43 Correct 174 ms 106844 KB Output is correct
44 Incorrect 2 ms 106844 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3310'
45 Halted 0 ms 0 KB -