Submission #51557

# Submission time Handle Problem Language Result Execution time Memory
51557 2018-06-18T14:47:27 Z aome Ancient Books (IOI17_books) C++17
50 / 100
312 ms 13628 KB
#include <bits/stdc++.h>
#include "books.h"
 
using namespace std;
 
const int N = 1000005;
 
bool visit[N];
 
long long minimum_walk(vector<int> p, int s) {
	long long optsum = 1e18;

	for (int l = 0; l <= s; ++l) {

		int n = p.size();
		int cur = l, lim = l;
		long long sum = 0;

		for (int i = 0; i < n; ++i) {
			sum += abs(p[i] - i);
			visit[i] = 0;
		}

		for (int i = l; i < n; ++i) {
			if (i != p[i]) lim = i;
		}

		while (1) {
			queue<int> qu;
			visit[cur] = 1, qu.push(cur);
	 
			while (qu.size()) {
				int u = qu.front(); qu.pop();
				while (cur < p[u]) {
					cur++, visit[cur] = 1, qu.push(cur);
				}
			}
	 
			if (cur == lim) break;
			sum += 2, cur++;
		}

		queue<int> qu;
		for (int i = 0; i < n; ++i) {
			if (visit[i]) qu.push(i);
		}

		while (qu.size()) {
			int u = qu.front(); qu.pop();
			if (!visit[p[u]]) {
				visit[p[u]] = 1, qu.push(p[u]);
			}
		}

		bool fail = 0;
		for (int i = 0; i < n; ++i) fail |= !visit[i] && i != p[i];

		if (!fail) optsum = min(optsum, sum);
	}

	return optsum;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 2 ms 536 KB Output is correct
10 Correct 3 ms 536 KB Output is correct
11 Correct 2 ms 536 KB Output is correct
12 Correct 3 ms 536 KB Output is correct
13 Correct 2 ms 536 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 2 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 2 ms 536 KB Output is correct
10 Correct 3 ms 536 KB Output is correct
11 Correct 2 ms 536 KB Output is correct
12 Correct 3 ms 536 KB Output is correct
13 Correct 2 ms 536 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 2 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 3 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 2 ms 740 KB Output is correct
29 Correct 2 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 2 ms 536 KB Output is correct
10 Correct 3 ms 536 KB Output is correct
11 Correct 2 ms 536 KB Output is correct
12 Correct 3 ms 536 KB Output is correct
13 Correct 2 ms 536 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 2 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 3 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 2 ms 740 KB Output is correct
29 Correct 2 ms 740 KB Output is correct
30 Correct 258 ms 13504 KB Output is correct
31 Correct 225 ms 13504 KB Output is correct
32 Correct 179 ms 13504 KB Output is correct
33 Correct 312 ms 13628 KB Output is correct
34 Correct 279 ms 13628 KB Output is correct
35 Correct 217 ms 13628 KB Output is correct
36 Correct 188 ms 13628 KB Output is correct
37 Correct 181 ms 13628 KB Output is correct
38 Correct 170 ms 13628 KB Output is correct
39 Correct 170 ms 13628 KB Output is correct
40 Correct 173 ms 13628 KB Output is correct
41 Correct 179 ms 13628 KB Output is correct
42 Correct 187 ms 13628 KB Output is correct
43 Correct 181 ms 13628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 13628 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 2 ms 536 KB Output is correct
10 Correct 3 ms 536 KB Output is correct
11 Correct 2 ms 536 KB Output is correct
12 Correct 3 ms 536 KB Output is correct
13 Correct 2 ms 536 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 2 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 3 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 2 ms 740 KB Output is correct
29 Correct 2 ms 740 KB Output is correct
30 Correct 258 ms 13504 KB Output is correct
31 Correct 225 ms 13504 KB Output is correct
32 Correct 179 ms 13504 KB Output is correct
33 Correct 312 ms 13628 KB Output is correct
34 Correct 279 ms 13628 KB Output is correct
35 Correct 217 ms 13628 KB Output is correct
36 Correct 188 ms 13628 KB Output is correct
37 Correct 181 ms 13628 KB Output is correct
38 Correct 170 ms 13628 KB Output is correct
39 Correct 170 ms 13628 KB Output is correct
40 Correct 173 ms 13628 KB Output is correct
41 Correct 179 ms 13628 KB Output is correct
42 Correct 187 ms 13628 KB Output is correct
43 Correct 181 ms 13628 KB Output is correct
44 Incorrect 34 ms 13628 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -