Submission #364618

# Submission time Handle Problem Language Result Execution time Memory
364618 2021-02-09T14:57:08 Z rqi Ancient Books (IOI17_books) C++14
50 / 100
181 ms 22892 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef long long ll;

#define sz(x) (int)(x).size()

long long minimum_walk(vi p, int s) {
	bool all_good = 1;
	for(int i = 0; i < sz(p); i++){
		if(p[i] != i) all_good = 0;
	}
	if(all_good) return 0;

	int n = sz(p);
	vi cover = vi(n, 0);
	vi dirover = vi(n, 0); //right = +1
	ll ans = 0;
	for(int i = 0; i < n; i++){
		cover[min(i, p[i])]++;
		cover[max(i, p[i])]--;
		dirover[i]++;
		dirover[p[i]]--;
		ans+=abs(p[i]-i);
	}

	//cout << ans << "\n";

	for(int i = 1; i < n; i++){
		cover[i]+=cover[i-1];
		dirover[i]+=dirover[i-1];
	}

	

	for(int i = 0; i < n; i++){
		ans+=abs(dirover[i]);
	}

	int L = 0;
	int R = n-2;
	for(int i = 0; i <= s-1; i++){
		if(p[i] == i){
			L = i+1;
		}
		else break;
	}
	for(int i = n-2; i >= s; i--){
		if(p[i+1] == i+1){
			R = i-1;
		}
		else break;
	}

	for(int i = L; i <= R; i++){
		if(cover[i] == 0){
			ans+=2;
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 164 ms 22764 KB Output is correct
31 Correct 166 ms 22796 KB Output is correct
32 Correct 126 ms 14828 KB Output is correct
33 Correct 139 ms 22764 KB Output is correct
34 Correct 145 ms 22764 KB Output is correct
35 Correct 146 ms 22764 KB Output is correct
36 Correct 145 ms 22764 KB Output is correct
37 Correct 149 ms 22892 KB Output is correct
38 Correct 148 ms 22764 KB Output is correct
39 Correct 145 ms 22732 KB Output is correct
40 Correct 146 ms 22764 KB Output is correct
41 Correct 147 ms 22764 KB Output is correct
42 Correct 181 ms 22764 KB Output is correct
43 Correct 144 ms 22764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 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 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 164 ms 22764 KB Output is correct
31 Correct 166 ms 22796 KB Output is correct
32 Correct 126 ms 14828 KB Output is correct
33 Correct 139 ms 22764 KB Output is correct
34 Correct 145 ms 22764 KB Output is correct
35 Correct 146 ms 22764 KB Output is correct
36 Correct 145 ms 22764 KB Output is correct
37 Correct 149 ms 22892 KB Output is correct
38 Correct 148 ms 22764 KB Output is correct
39 Correct 145 ms 22732 KB Output is correct
40 Correct 146 ms 22764 KB Output is correct
41 Correct 147 ms 22764 KB Output is correct
42 Correct 181 ms 22764 KB Output is correct
43 Correct 144 ms 22764 KB Output is correct
44 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -