Submission #70240

# Submission time Handle Problem Language Result Execution time Memory
70240 2018-08-22T14:02:19 Z E869120 Ancient Books (IOI17_books) C++14
50 / 100
303 ms 107868 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

int n,c[1000009];bool used[1000009];

long long minimum_walk(vector<int> p, int s) {
	n=p.size();
	long long sum=0;
	for(int i=0;i<n;i++){
		if(used[i]==true || i==p[i]) continue;
		int cx=i, maxn=0;
		while(true){
			sum+=abs(cx-p[cx]);used[cx]=true;maxn=max(maxn,cx);
			cx=p[cx];if(cx==i) break;
		}
		c[i]++;c[maxn]--;
	}
	for(int i=1;i<=n;i++) c[i]+=c[i-1];
	long long L=0;bool flag=false;
	for(int i=n;i>=0;i--){
		if(c[i]==1) flag=true;
		if(flag==true && c[i]==0) L++;
	}
	return sum+L*2;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 2 ms 660 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 2 ms 660 KB Output is correct
15 Correct 3 ms 660 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 3 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 2 ms 660 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 2 ms 660 KB Output is correct
15 Correct 3 ms 660 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 3 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 3 ms 684 KB Output is correct
21 Correct 3 ms 684 KB Output is correct
22 Correct 2 ms 684 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 776 KB Output is correct
25 Correct 3 ms 776 KB Output is correct
26 Correct 2 ms 788 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 788 KB Output is correct
29 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 2 ms 660 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 2 ms 660 KB Output is correct
15 Correct 3 ms 660 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 3 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 3 ms 684 KB Output is correct
21 Correct 3 ms 684 KB Output is correct
22 Correct 2 ms 684 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 776 KB Output is correct
25 Correct 3 ms 776 KB Output is correct
26 Correct 2 ms 788 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 788 KB Output is correct
29 Correct 2 ms 788 KB Output is correct
30 Correct 303 ms 20116 KB Output is correct
31 Correct 258 ms 26920 KB Output is correct
32 Correct 182 ms 32640 KB Output is correct
33 Correct 228 ms 40408 KB Output is correct
34 Correct 195 ms 47228 KB Output is correct
35 Correct 192 ms 53968 KB Output is correct
36 Correct 185 ms 60624 KB Output is correct
37 Correct 159 ms 67260 KB Output is correct
38 Correct 179 ms 74128 KB Output is correct
39 Correct 179 ms 80836 KB Output is correct
40 Correct 196 ms 87568 KB Output is correct
41 Correct 229 ms 94380 KB Output is correct
42 Correct 216 ms 101120 KB Output is correct
43 Correct 184 ms 107868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 107868 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 3 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 2 ms 660 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 2 ms 660 KB Output is correct
15 Correct 3 ms 660 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 3 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 3 ms 684 KB Output is correct
21 Correct 3 ms 684 KB Output is correct
22 Correct 2 ms 684 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 776 KB Output is correct
25 Correct 3 ms 776 KB Output is correct
26 Correct 2 ms 788 KB Output is correct
27 Correct 2 ms 788 KB Output is correct
28 Correct 2 ms 788 KB Output is correct
29 Correct 2 ms 788 KB Output is correct
30 Correct 303 ms 20116 KB Output is correct
31 Correct 258 ms 26920 KB Output is correct
32 Correct 182 ms 32640 KB Output is correct
33 Correct 228 ms 40408 KB Output is correct
34 Correct 195 ms 47228 KB Output is correct
35 Correct 192 ms 53968 KB Output is correct
36 Correct 185 ms 60624 KB Output is correct
37 Correct 159 ms 67260 KB Output is correct
38 Correct 179 ms 74128 KB Output is correct
39 Correct 179 ms 80836 KB Output is correct
40 Correct 196 ms 87568 KB Output is correct
41 Correct 229 ms 94380 KB Output is correct
42 Correct 216 ms 101120 KB Output is correct
43 Correct 184 ms 107868 KB Output is correct
44 Incorrect 2 ms 107868 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -