Submission #1029155

# Submission time Handle Problem Language Result Execution time Memory
1029155 2024-07-20T13:05:16 Z amirhoseinfar1385 Ancient Books (IOI17_books) C++17
50 / 100
111 ms 34388 KB
#include"books.h"
#include <vector>
#include<bits/stdc++.h>
const int maxn=1000000+10;
using namespace std;
int vis[maxn],visa[maxn],av[maxn],tr[maxn];
int n;
long long mainres=0,last=0;
vector<pair<int,pair<int,int>>>alle;

struct dsu{
	int par[maxn];
	dsu(){
		for(int i=0;i<maxn;i++){
			par[i]=i;
		}
	}
	void clear(){
		for(int i=0;i<maxn;i++){
			par[i]=i;
		}
	}	
	int root(int u){
		if(u==par[u]){
			return u;
		}
		return par[u]=root(par[u]);
	}
	int con(int u,int v){
		u=root(u);
		v=root(v);
		if(u==v){
			return 0;
		}
		par[u]=v;
		return 1;
	}
}ds;

void mst(){
	ds.clear();
	sort(alle.begin(),alle.end());
	for(int i=0;i<(int)alle.size();i++){
		if(ds.con(alle[i].second.first,alle[i].second.second)){
			mainres+=alle[i].first;
		}
	}
}

long long minimum_walk(std::vector<int> p, int s){
	mainres=0;
	n=p.size();
	for(int i=0;i<=n;i++){
		vis[i]=visa[i]=0;
	}
	last=0;
	int cnt1=0;
	for(int i=0;i<n;i++){
		if(p[i]>i){
			cnt1++;
			visa[p[i]]=1;
		}
		if(visa[i]){
			cnt1--;
		}
		mainres+=cnt1*2;
		if(cnt1!=0){
			last=i+1;
		}
	}
	for(int i=0;i<n;i++){
		if(i==p[i]){
			continue;
		}
		if(vis[i]==0){
			//mainres+=2;
			int now=i;
			do{
				av[now]=i;
				vis[now]=1;
				tr[i]=max(tr[i],now);
				now=p[now];
			}while(now!=i);
		}
	}
	last=-1;
	alle.clear();
	int mx=0;
	for(int i=0;i<n;i++){
		if(i==p[i]){
			continue;
		}
		if(i<=mx){
			mx=max(mx,tr[i]);
		}else{
			mainres+=(i-mx)*2;
			mx=max(mx,tr[i]);
		}
	}
	return mainres;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4348 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4348 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4196 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4292 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 2 ms 4188 KB Output is correct
26 Correct 2 ms 4188 KB Output is correct
27 Correct 2 ms 4188 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4348 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4196 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4292 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 2 ms 4188 KB Output is correct
26 Correct 2 ms 4188 KB Output is correct
27 Correct 2 ms 4188 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Correct 2 ms 4188 KB Output is correct
30 Correct 103 ms 30544 KB Output is correct
31 Correct 111 ms 30508 KB Output is correct
32 Correct 79 ms 26544 KB Output is correct
33 Correct 82 ms 34384 KB Output is correct
34 Correct 81 ms 34372 KB Output is correct
35 Correct 94 ms 34388 KB Output is correct
36 Correct 91 ms 34364 KB Output is correct
37 Correct 79 ms 34384 KB Output is correct
38 Correct 81 ms 33620 KB Output is correct
39 Correct 81 ms 33336 KB Output is correct
40 Correct 81 ms 31420 KB Output is correct
41 Correct 101 ms 30532 KB Output is correct
42 Correct 92 ms 30800 KB Output is correct
43 Correct 90 ms 34384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4188 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 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4348 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4196 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4292 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 2 ms 4188 KB Output is correct
26 Correct 2 ms 4188 KB Output is correct
27 Correct 2 ms 4188 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Correct 2 ms 4188 KB Output is correct
30 Correct 103 ms 30544 KB Output is correct
31 Correct 111 ms 30508 KB Output is correct
32 Correct 79 ms 26544 KB Output is correct
33 Correct 82 ms 34384 KB Output is correct
34 Correct 81 ms 34372 KB Output is correct
35 Correct 94 ms 34388 KB Output is correct
36 Correct 91 ms 34364 KB Output is correct
37 Correct 79 ms 34384 KB Output is correct
38 Correct 81 ms 33620 KB Output is correct
39 Correct 81 ms 33336 KB Output is correct
40 Correct 81 ms 31420 KB Output is correct
41 Correct 101 ms 30532 KB Output is correct
42 Correct 92 ms 30800 KB Output is correct
43 Correct 90 ms 34384 KB Output is correct
44 Incorrect 2 ms 4188 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -