답안 #41001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41001 2018-02-11T08:59:44 Z alenam0161 고대 책들 (IOI17_books) C++14
50 / 100
232 ms 111888 KB
#include "books.h"
#include <vector>
#include <algorithm>

using namespace std;
const int N = 1e6 + 7;
int group[N];
int mx[N];
bool used[N];
long long minimum_walk(std::vector<int> p, int s) {
	long long ans = 0;
	for (int i = 0; i < p.size(); ++i) {
		int to = i;
		if (used[to])continue;
		while (true) {
			group[to] = i;
			mx[i] = max(mx[i], to);
			ans += abs(p[to] - to);
			used[to] = true;
			if (used[p[to]])break;
			to = p[to];
		}
	}
	int Mx = 0;
	for (int i = 0; i < p.size(); ++i) {
		if (Mx == -1) { ans += 2; Mx = mx[i]; }
		else {
			Mx = max(Mx, mx[i]);
		}
		if (Mx == i)Mx = -1;
	}
	for (int i = p.size() - 1; i > 0; i--) { if (p[i] != i)break; ans -= 2; }

	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p.size(); ++i) {
                    ^
books.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p.size(); ++i) {
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 2 ms 780 KB Output is correct
9 Correct 1 ms 780 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 1 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 1 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 2 ms 780 KB Output is correct
9 Correct 1 ms 780 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 1 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 1 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 920 KB Output is correct
21 Correct 1 ms 920 KB Output is correct
22 Correct 1 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 1 ms 920 KB Output is correct
27 Correct 2 ms 920 KB Output is correct
28 Correct 2 ms 924 KB Output is correct
29 Correct 1 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 2 ms 780 KB Output is correct
9 Correct 1 ms 780 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 1 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 1 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 920 KB Output is correct
21 Correct 1 ms 920 KB Output is correct
22 Correct 1 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 1 ms 920 KB Output is correct
27 Correct 2 ms 920 KB Output is correct
28 Correct 2 ms 924 KB Output is correct
29 Correct 1 ms 924 KB Output is correct
30 Correct 203 ms 20308 KB Output is correct
31 Correct 232 ms 27068 KB Output is correct
32 Correct 149 ms 37796 KB Output is correct
33 Correct 151 ms 44524 KB Output is correct
34 Correct 147 ms 51320 KB Output is correct
35 Correct 152 ms 57884 KB Output is correct
36 Correct 159 ms 64676 KB Output is correct
37 Correct 152 ms 71428 KB Output is correct
38 Correct 159 ms 77604 KB Output is correct
39 Correct 152 ms 84092 KB Output is correct
40 Correct 165 ms 88712 KB Output is correct
41 Correct 213 ms 94576 KB Output is correct
42 Correct 184 ms 101524 KB Output is correct
43 Correct 194 ms 111888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 111888 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 2 ms 780 KB Output is correct
9 Correct 1 ms 780 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 1 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 1 ms 824 KB Output is correct
14 Correct 2 ms 824 KB Output is correct
15 Correct 2 ms 824 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 920 KB Output is correct
21 Correct 1 ms 920 KB Output is correct
22 Correct 1 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 1 ms 920 KB Output is correct
27 Correct 2 ms 920 KB Output is correct
28 Correct 2 ms 924 KB Output is correct
29 Correct 1 ms 924 KB Output is correct
30 Correct 203 ms 20308 KB Output is correct
31 Correct 232 ms 27068 KB Output is correct
32 Correct 149 ms 37796 KB Output is correct
33 Correct 151 ms 44524 KB Output is correct
34 Correct 147 ms 51320 KB Output is correct
35 Correct 152 ms 57884 KB Output is correct
36 Correct 159 ms 64676 KB Output is correct
37 Correct 152 ms 71428 KB Output is correct
38 Correct 159 ms 77604 KB Output is correct
39 Correct 152 ms 84092 KB Output is correct
40 Correct 165 ms 88712 KB Output is correct
41 Correct 213 ms 94576 KB Output is correct
42 Correct 184 ms 101524 KB Output is correct
43 Correct 194 ms 111888 KB Output is correct
44 Incorrect 1 ms 111888 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -