Submission #780575

# Submission time Handle Problem Language Result Execution time Memory
780575 2023-07-12T10:23:43 Z CSQ31 Ancient Books (IOI17_books) C++17
50 / 100
108 ms 20344 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef long long int ll;
typedef pair<int,int> pii;
const int MAXN = 1e6+1;
int par[MAXN];
int find(int x){
	if(x==par[x])return x;
	return par[x] = find(par[x]);
}
ll minimum_walk(vector<int> p, int s) {
	int n = sz(p);
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans+=abs(i-p[i]);
		par[i] = i;
	}
	for(int i=0;i<n;i++){
		if(i==p[i])continue;
		int mn = min(i,p[i]);
		int mx = max(i,p[i]);
		
		int j = mn;
		while(find(j)+1 <= mx){
			j = find(j);
			par[j] = j+1;
		}
	}
	vector<pii>lf,rg;
	pii md = {-1,-1};
	rg.pb({s,s});
	for(int i=0;i<n;i++){
		if(i==p[i])continue;
		int j = i;
		while(j+1<n && find(i) == find(j+1))j++;
		if(j<=s)lf.pb({i,j});
		else if(i>=s)rg.pb({i,j});
		else md = {i,j};
		i = j;
	}
	lf.pb({s,s});
	ll add = 0;
	if(md.fi != -1)add+=min(s-md.fi,md.se-s);
	for(int i=0;i+1<sz(lf);i++)add+=lf[i+1].fi - lf[i].se;
	for(int i=0;i+1<sz(rg);i++)add+=rg[i+1].fi - rg[i].se;
	ans+=2*add;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 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 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 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 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
27 Correct 0 ms 212 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 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 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 107 ms 20344 KB Output is correct
31 Correct 93 ms 19068 KB Output is correct
32 Correct 80 ms 12028 KB Output is correct
33 Correct 84 ms 14188 KB Output is correct
34 Correct 85 ms 14188 KB Output is correct
35 Correct 89 ms 14200 KB Output is correct
36 Correct 96 ms 13172 KB Output is correct
37 Correct 86 ms 12056 KB Output is correct
38 Correct 108 ms 12056 KB Output is correct
39 Correct 104 ms 12112 KB Output is correct
40 Correct 85 ms 12464 KB Output is correct
41 Correct 94 ms 18320 KB Output is correct
42 Correct 88 ms 15224 KB Output is correct
43 Correct 89 ms 20340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3594'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 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 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 107 ms 20344 KB Output is correct
31 Correct 93 ms 19068 KB Output is correct
32 Correct 80 ms 12028 KB Output is correct
33 Correct 84 ms 14188 KB Output is correct
34 Correct 85 ms 14188 KB Output is correct
35 Correct 89 ms 14200 KB Output is correct
36 Correct 96 ms 13172 KB Output is correct
37 Correct 86 ms 12056 KB Output is correct
38 Correct 108 ms 12056 KB Output is correct
39 Correct 104 ms 12112 KB Output is correct
40 Correct 85 ms 12464 KB Output is correct
41 Correct 94 ms 18320 KB Output is correct
42 Correct 88 ms 15224 KB Output is correct
43 Correct 89 ms 20340 KB Output is correct
44 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3594'
45 Halted 0 ms 0 KB -