Submission #983991

# Submission time Handle Problem Language Result Execution time Memory
983991 2024-05-16T08:59:54 Z CSQ31 Ancient Books (IOI17_books) C++17
50 / 100
109 ms 34932 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 mn[MAXN],mx[MAXN];

int find(int x){
	if(x==par[x])return x;
	return par[x] = find(par[x]);
}

void unite(int a,int b){
	a = find(a);
	b = find(b);
	if(a==b)return;
	mx[b] = max(mx[b],mx[a]);
	mn[b] = min(mn[b],mn[a]);
	par[a] = b;
}

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]);
	for(int i=0;i<n;i++){
		par[i] = i;
		mn[i] = min(i,p[i]);
		mx[i] = max(i,p[i]);
	}

	for(int i=0;i<n;i++){
		int l = min(i,p[i]);
		int r = max(i,p[i]);
		if(l==r)continue;

		while(true){
			l = find(l);
			if(l >= r)break;
			unite(l,l+1);
			l = find(l);
		}
	}
	int cur = 0;
	while(true){
		int nxt = cur;
		while(nxt < n){
			if(find(nxt) > nxt)break;
			nxt++;
		}
		if(nxt == n)break;
		ans += 2*(nxt - cur);
		cur = find(nxt);
	}
	return ans;	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4472 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4540 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4472 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4540 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4688 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4472 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4540 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4688 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 102 ms 34896 KB Output is correct
31 Correct 105 ms 33616 KB Output is correct
32 Correct 78 ms 26708 KB Output is correct
33 Correct 88 ms 26708 KB Output is correct
34 Correct 87 ms 26704 KB Output is correct
35 Correct 92 ms 26720 KB Output is correct
36 Correct 102 ms 26704 KB Output is correct
37 Correct 96 ms 26492 KB Output is correct
38 Correct 95 ms 26744 KB Output is correct
39 Correct 96 ms 26596 KB Output is correct
40 Correct 93 ms 27128 KB Output is correct
41 Correct 96 ms 32848 KB Output is correct
42 Correct 109 ms 29928 KB Output is correct
43 Correct 105 ms 34932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 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 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4472 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4540 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4688 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 102 ms 34896 KB Output is correct
31 Correct 105 ms 33616 KB Output is correct
32 Correct 78 ms 26708 KB Output is correct
33 Correct 88 ms 26708 KB Output is correct
34 Correct 87 ms 26704 KB Output is correct
35 Correct 92 ms 26720 KB Output is correct
36 Correct 102 ms 26704 KB Output is correct
37 Correct 96 ms 26492 KB Output is correct
38 Correct 95 ms 26744 KB Output is correct
39 Correct 96 ms 26596 KB Output is correct
40 Correct 93 ms 27128 KB Output is correct
41 Correct 96 ms 32848 KB Output is correct
42 Correct 109 ms 29928 KB Output is correct
43 Correct 105 ms 34932 KB Output is correct
44 Incorrect 1 ms 4444 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -