답안 #424812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424812 2021-06-12T10:32:28 Z saleh 고대 책들 (IOI17_books) C++17
50 / 100
217 ms 25336 KB
#include "books.h"
#include <bits/stdc++.h>

#define ft first
#define sd second
#define int long long
using namespace std;

typedef pair<int, int> pii;

const int MAXN = 1000 * 1000 + 23;


int mark[MAXN], cnt = 0, ans, jav, ma[MAXN];

long long minimum_walk(std::vector<int32_t> p, int32_t s) {
	if (s != 0) return 0;
	int n = p.size();
	for (int i = 0; i < n; i++) if (p[i] != i && mark[i] == 0) {
		int tmp = i, pre = i, mx = i;
		mark[i] = ++cnt;
		while ((tmp = p[tmp]) != i) {
			mark[tmp] = cnt;
			jav += abs(pre - tmp);
			pre = tmp;
			mx = max(mx, tmp);
		}
		ma[i + 1]++; ma[mx + 1]--;
		jav += abs(i - pre);
		ans = max(ans, i);
	}
	for (int i = 1; i <= ans; i++) {
		ma[i] += ma[i - 1];
		if (ma[i] == 0) jav += 2;
	}
//	cout << jav << ' ' << ans << endl;
	return jav;
}

//int main() {cout << minimum_walk({0, 2, 3, 1}, 0); }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 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 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 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 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 166 ms 17012 KB Output is correct
31 Correct 168 ms 17768 KB Output is correct
32 Correct 114 ms 9648 KB Output is correct
33 Correct 132 ms 25284 KB Output is correct
34 Correct 129 ms 25284 KB Output is correct
35 Correct 135 ms 25320 KB Output is correct
36 Correct 134 ms 25336 KB Output is correct
37 Correct 173 ms 25324 KB Output is correct
38 Correct 127 ms 25268 KB Output is correct
39 Correct 135 ms 25260 KB Output is correct
40 Correct 130 ms 25264 KB Output is correct
41 Correct 217 ms 24544 KB Output is correct
42 Correct 140 ms 25320 KB Output is correct
43 Correct 130 ms 25304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 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 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 166 ms 17012 KB Output is correct
31 Correct 168 ms 17768 KB Output is correct
32 Correct 114 ms 9648 KB Output is correct
33 Correct 132 ms 25284 KB Output is correct
34 Correct 129 ms 25284 KB Output is correct
35 Correct 135 ms 25320 KB Output is correct
36 Correct 134 ms 25336 KB Output is correct
37 Correct 173 ms 25324 KB Output is correct
38 Correct 127 ms 25268 KB Output is correct
39 Correct 135 ms 25260 KB Output is correct
40 Correct 130 ms 25264 KB Output is correct
41 Correct 217 ms 24544 KB Output is correct
42 Correct 140 ms 25320 KB Output is correct
43 Correct 130 ms 25304 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
45 Halted 0 ms 0 KB -