Submission #1104918

# Submission time Handle Problem Language Result Execution time Memory
1104918 2024-10-24T17:28:19 Z alexander707070 Ancient Books (IOI17_books) C++14
50 / 100
96 ms 23800 KB
#include<bits/stdc++.h>
#define MAXN 1000007
using namespace std;

int n,s,p[MAXN],last,mins,maxs,pref[MAXN],curr;
bool li[MAXN];
long long ans;

void dfs(int x){
	li[x]=true;

	ans+=abs(x-p[x]);
	mins=min(mins,x);
	maxs=max(maxs,x);

	if(!li[p[x]])dfs(p[x]);
}

long long minimum_walk(vector<int> P, int S){
	n=int(P.size()); s=S+1;

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

	for(int i=1;i<=n;i++){
		if(!li[i]){
			if(p[i]!=i)last=i;
			mins=n; maxs=1;
			dfs(i);

			pref[mins]++; pref[maxs]--;
		}
	}

	for(int i=1;i<=n-1;i++){
		curr+=pref[i];
		if(curr==0 and last>i)ans+=2;
	}

	return ans;
}

/*int main(){

	cout<<minimum_walk({0, 2, 3, 1}, 0)<<"\n";

	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4684 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4600 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4684 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4600 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4556 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4604 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4684 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4600 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4556 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4604 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4432 KB Output is correct
30 Correct 95 ms 15624 KB Output is correct
31 Correct 88 ms 20472 KB Output is correct
32 Correct 74 ms 23668 KB Output is correct
33 Correct 77 ms 23628 KB Output is correct
34 Correct 77 ms 23624 KB Output is correct
35 Correct 79 ms 23624 KB Output is correct
36 Correct 76 ms 23800 KB Output is correct
37 Correct 73 ms 23624 KB Output is correct
38 Correct 78 ms 23624 KB Output is correct
39 Correct 72 ms 23636 KB Output is correct
40 Correct 77 ms 23624 KB Output is correct
41 Correct 93 ms 22600 KB Output is correct
42 Correct 96 ms 23624 KB Output is correct
43 Correct 78 ms 23668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4432 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 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4684 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4600 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4556 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4604 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4432 KB Output is correct
30 Correct 95 ms 15624 KB Output is correct
31 Correct 88 ms 20472 KB Output is correct
32 Correct 74 ms 23668 KB Output is correct
33 Correct 77 ms 23628 KB Output is correct
34 Correct 77 ms 23624 KB Output is correct
35 Correct 79 ms 23624 KB Output is correct
36 Correct 76 ms 23800 KB Output is correct
37 Correct 73 ms 23624 KB Output is correct
38 Correct 78 ms 23624 KB Output is correct
39 Correct 72 ms 23636 KB Output is correct
40 Correct 77 ms 23624 KB Output is correct
41 Correct 93 ms 22600 KB Output is correct
42 Correct 96 ms 23624 KB Output is correct
43 Correct 78 ms 23668 KB Output is correct
44 Incorrect 1 ms 4432 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -