Submission #600847

# Submission time Handle Problem Language Result Execution time Memory
600847 2022-07-21T08:17:17 Z Lucpp Ancient Books (IOI17_books) C++17
50 / 100
131 ms 14988 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

long long minimum_walk(vector<int> p, int s){
	int n = (int)p.size();
	ll ans = 0;
	vector<bool> vis(n);
	int mi = s, ma = s;
	int l = s, r = s;
	while(true){
		int i = -1;
		while(r <= ma){
			if(!vis[r]){
				i = r;
				break;
			}
			r++;
		}
		if(i != -1)
		while(l >= mi){
			if(!vis[l]){
				i = l;
				break;
			}
			l--; 
		}
		if(i == -1){
			int oldR = r, oldL = l;
			while(r < n){
				if(!vis[r] && p[r] != r){
					i = r;
					ans += 2*(r+1-oldR);
					break;
				}
				r++;
			}
			if(i == -1)
			while(l >= 0){
				if(!vis[l] && p[l] != l){
					i = l;
					ans += 2*(oldL+1-l);
					break;
				}
				l--;
			}
			if(i == -1) break;
		}
		int j = i;
		do
		{
			vis[j] = true;
			mi = min(mi, p[j]);
			ma = max(ma, p[j]);
			ans += abs(j-p[j]);
			j = p[j];
		}while(j != i);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 114 ms 14988 KB Output is correct
31 Correct 111 ms 14952 KB Output is correct
32 Correct 98 ms 14940 KB Output is correct
33 Correct 91 ms 14980 KB Output is correct
34 Correct 87 ms 14944 KB Output is correct
35 Correct 116 ms 14948 KB Output is correct
36 Correct 103 ms 14960 KB Output is correct
37 Correct 85 ms 14952 KB Output is correct
38 Correct 87 ms 14956 KB Output is correct
39 Correct 131 ms 14940 KB Output is correct
40 Correct 115 ms 14956 KB Output is correct
41 Correct 96 ms 14944 KB Output is correct
42 Correct 105 ms 14988 KB Output is correct
43 Correct 92 ms 14948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4504'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 114 ms 14988 KB Output is correct
31 Correct 111 ms 14952 KB Output is correct
32 Correct 98 ms 14940 KB Output is correct
33 Correct 91 ms 14980 KB Output is correct
34 Correct 87 ms 14944 KB Output is correct
35 Correct 116 ms 14948 KB Output is correct
36 Correct 103 ms 14960 KB Output is correct
37 Correct 85 ms 14952 KB Output is correct
38 Correct 87 ms 14956 KB Output is correct
39 Correct 131 ms 14940 KB Output is correct
40 Correct 115 ms 14956 KB Output is correct
41 Correct 96 ms 14944 KB Output is correct
42 Correct 105 ms 14988 KB Output is correct
43 Correct 92 ms 14948 KB Output is correct
44 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4504'
45 Halted 0 ms 0 KB -