Submission #447805

# Submission time Handle Problem Language Result Execution time Memory
447805 2021-07-27T14:52:40 Z mosiashvililuka Fountain Parks (IOI21_parks) C++17
55 / 100
1512 ms 167752 KB
#include<bits/stdc++.h>
#include "parks.h"
#define mk make_pair
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,PI,cc,dd,cnt,CNT,bo[1000009];
pair <int, int> p[200009],P[1000009];
vector <pair <int, int> > X[200009],Y[200009];
vector <int> U,V,A,B;
map <int, int> m[200009],M[200009];
set <pair <int, pair <int, int> > > s;
set <pair <int, pair <int, int> > >::iterator it;
vector <int> v[1000009];
pair <int, int> id[1000009];
void DONE(){
	s.erase(s.lower_bound(make_pair(M[cc][dd],make_pair(cc,dd))));
	M[cc][dd]--;
	s.insert(mk(M[cc][dd],mk(cc,dd)));
}
void chk(int q, int w){
	if(m[q][w]==0) return;
	i=m[q][w];c=P[i].first;d=P[i].second;
	U.push_back(c);V.push_back(d);A.push_back(zx);B.push_back(xc);
	if(p[c].first==p[d].first){
		cc=p[c].first-1;dd=(p[c].second+p[d].second)/2;
		DONE();
		cc=p[c].first+1;dd=(p[c].second+p[d].second)/2;
		DONE();
	}else{
		cc=(p[c].first+p[d].first)/2;dd=p[c].second-1;
		DONE();
		cc=(p[c].first+p[d].first)/2;dd=p[c].second+1;
		DONE();
	}
	m[q][w]=0;
}
void DOO(){
	if(M[cc][dd]!=0){
		s.erase(s.lower_bound(make_pair(M[cc][dd],make_pair(cc,dd))));
	}
	M[cc][dd]++;
	s.insert(make_pair(M[cc][dd],make_pair(cc,dd)));
}
void CHK(int q, int w){
	if(m[q][w]==0) return;
	v[m[q][w]].push_back(cnt);
	v[cnt].push_back(m[q][w]);
}
void dfs(int q, int w){
	bo[q]=1;
	if(q<=PI){
		c=P[q].first;d=P[q].second;
		U.push_back(c);V.push_back(d);A.push_back(id[w].first);B.push_back(id[w].second);
	}
	for(vector <int>::iterator tt=v[q].begin(); tt!=v[q].end(); tt++){
		if(bo[(*tt)]==1) continue;
		dfs((*tt),q);
	}
}



int msh[200009],zm[200009];
int fnd(int q){
	if(msh[q]==0) return q; else return msh[q]=fnd(msh[q]);
}
void mrg(int  q, int w){
	q=fnd(q);w=fnd(w);if(q==w) return;if(zm[q]<zm[q]) swap(q,w);
	msh[w]=q;if(zm[q]==zm[w]) zm[q]++;
}
bool check(){
	set <int> st;
	for(i=1; i<=PI; i++){
		mrg(P[i].first,P[i].second);
	}
	for(i=1; i<=a; i++) st.insert(fnd(i));
	if(st.size()==1) return 1; else return 0;
}
int construct_roads(std::vector<int> Xx, std::vector<int> Yy) {
    a=Xx.size();
    for(i=1; i<=a; i++){
    	p[i].first=Xx[i-1];p[i].second=Yy[i-1];
	}
	for(i=1; i<=a; i++){
		X[p[i].first].push_back(make_pair(p[i].second,i));
		Y[p[i].second].push_back(make_pair(p[i].first,i));
	}
	for(i=2; i<=200000; i+=2){
		sort(X[i].begin(),X[i].end());
		sort(Y[i].begin(),Y[i].end());
		e=X[i].size();
		for(j=0; j<e-1; j++){
			if(X[i][j].first+2<X[i][j+1].first) continue;
			//cout<<i<<"  "<<X[i][j].first<<" X "<<X[i][j+1].first<<endl;
			c=X[i][j].second;d=X[i][j+1].second;
			PI++;
			P[PI].first=c;P[PI].second=d;
		}
		e=Y[i].size();
		for(j=0; j<e-1; j++){
			if(Y[i][j].first+2<Y[i][j+1].first) continue;
			//cout<<i<<"  "<<Y[i][j].first<<" Y "<<Y[i][j+1].first<<endl;
			c=Y[i][j].second;d=Y[i][j+1].second;
			PI++;
			P[PI].first=c;P[PI].second=d;
		}
	}
	if(check()==0){
		return 0;
	}
	/*cout<<PI<<endl;
	for(i=1; i<=PI; i++){
		c=P[i].first;d=P[i].second;
		cout<<p[c].first<<" "<<p[c].second<<"   "<<p[d].first<<" "<<p[d].second<<endl;
	}
	exit(0);*/
	for(i=1; i<=PI; i++){
		c=P[i].first;d=P[i].second;
		m[(p[c].first+p[d].first)/2][(p[c].second+p[d].second)/2]=i;
		if(p[c].first==p[d].first){
			cc=p[c].first-1;dd=(p[c].second+p[d].second)/2;
			DOO();
			cc=p[c].first+1;dd=(p[c].second+p[d].second)/2;
			DOO();
		}else{
			cc=(p[c].first+p[d].first)/2;dd=p[c].second-1;
			DOO();
			cc=(p[c].first+p[d].first)/2;dd=p[c].second+1;
			DOO();
		}
	}
	while(s.size()){
		it=s.begin();
		if((*it).first>=2) break;
		if((*it).first==0){
			s.erase(it);continue;
		}
		int ca=(*it).second.first,da=(*it).second.second;
		zx=ca;xc=da;
		chk(ca-1,da);chk(ca+1,da);chk(ca,da-1);chk(ca,da+1);
	}
	/*cout<<U.size()<<endl;
	for(i=0; i<U.size(); i++){
		cout<<U[i]<<" "<<V[i]<<" "<<A[i]<<" "<<B[i]<<endl;
	}
	exit(0);*/
	cnt=PI+1;
	for(it=s.begin(); it!=s.end(); it++){
		cnt++;id[cnt]=(*it).second;
		CHK((*it).second.first-1,(*it).second.second);
		CHK((*it).second.first+1,(*it).second.second);
		CHK((*it).second.first,(*it).second.second-1);
		CHK((*it).second.first,(*it).second.second+1);
	}
	for(i=PI+1; i<=cnt; i++){
		if(bo[i]!=0) continue;
		dfs(i,0);
	}
	
	for(i=0; i<U.size(); i++){
		U[i]--;V[i]--;
	}
	build(U,V,A,B);
    return 1;
}

Compilation message

parks.cpp: In function 'void mrg(int, int)':
parks.cpp:67:44: warning: self-comparison always evaluates to false [-Wtautological-compare]
   67 |  q=fnd(q);w=fnd(w);if(q==w) return;if(zm[q]<zm[q]) swap(q,w);
      |                                       ~~~~~^~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:159:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |  for(i=0; i<U.size(); i++){
      |           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
17 Correct 28 ms 51916 KB Output is correct
18 Correct 29 ms 51976 KB Output is correct
19 Correct 29 ms 52000 KB Output is correct
20 Correct 29 ms 51940 KB Output is correct
21 Correct 30 ms 51908 KB Output is correct
22 Correct 29 ms 51916 KB Output is correct
23 Correct 1512 ms 134172 KB Output is correct
24 Correct 29 ms 51924 KB Output is correct
25 Correct 34 ms 52488 KB Output is correct
26 Correct 30 ms 52104 KB Output is correct
27 Correct 30 ms 52256 KB Output is correct
28 Correct 556 ms 84536 KB Output is correct
29 Correct 868 ms 101148 KB Output is correct
30 Correct 1199 ms 117300 KB Output is correct
31 Correct 1493 ms 134144 KB Output is correct
32 Correct 29 ms 51908 KB Output is correct
33 Correct 29 ms 51916 KB Output is correct
34 Correct 29 ms 51932 KB Output is correct
35 Correct 28 ms 51960 KB Output is correct
36 Correct 29 ms 51856 KB Output is correct
37 Correct 29 ms 51908 KB Output is correct
38 Correct 28 ms 51952 KB Output is correct
39 Correct 28 ms 51916 KB Output is correct
40 Correct 28 ms 51912 KB Output is correct
41 Correct 29 ms 51868 KB Output is correct
42 Correct 29 ms 51984 KB Output is correct
43 Correct 29 ms 52064 KB Output is correct
44 Correct 31 ms 52228 KB Output is correct
45 Correct 535 ms 87176 KB Output is correct
46 Correct 790 ms 104236 KB Output is correct
47 Correct 777 ms 104048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
17 Correct 28 ms 51916 KB Output is correct
18 Correct 29 ms 51976 KB Output is correct
19 Correct 29 ms 52000 KB Output is correct
20 Correct 29 ms 51940 KB Output is correct
21 Correct 30 ms 51908 KB Output is correct
22 Correct 29 ms 51916 KB Output is correct
23 Correct 1512 ms 134172 KB Output is correct
24 Correct 29 ms 51924 KB Output is correct
25 Correct 34 ms 52488 KB Output is correct
26 Correct 30 ms 52104 KB Output is correct
27 Correct 30 ms 52256 KB Output is correct
28 Correct 556 ms 84536 KB Output is correct
29 Correct 868 ms 101148 KB Output is correct
30 Correct 1199 ms 117300 KB Output is correct
31 Correct 1493 ms 134144 KB Output is correct
32 Correct 29 ms 51908 KB Output is correct
33 Correct 29 ms 51916 KB Output is correct
34 Correct 29 ms 51932 KB Output is correct
35 Correct 28 ms 51960 KB Output is correct
36 Correct 29 ms 51856 KB Output is correct
37 Correct 29 ms 51908 KB Output is correct
38 Correct 28 ms 51952 KB Output is correct
39 Correct 28 ms 51916 KB Output is correct
40 Correct 28 ms 51912 KB Output is correct
41 Correct 29 ms 51868 KB Output is correct
42 Correct 29 ms 51984 KB Output is correct
43 Correct 29 ms 52064 KB Output is correct
44 Correct 31 ms 52228 KB Output is correct
45 Correct 535 ms 87176 KB Output is correct
46 Correct 790 ms 104236 KB Output is correct
47 Correct 777 ms 104048 KB Output is correct
48 Correct 30 ms 51884 KB Output is correct
49 Correct 29 ms 51916 KB Output is correct
50 Correct 28 ms 51900 KB Output is correct
51 Correct 31 ms 51948 KB Output is correct
52 Correct 29 ms 51884 KB Output is correct
53 Correct 29 ms 51928 KB Output is correct
54 Correct 29 ms 51972 KB Output is correct
55 Incorrect 1410 ms 164168 KB Tree @(3, 5) appears more than once: for edges on positions 133337 and 133338
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
17 Correct 27 ms 51960 KB Output is correct
18 Correct 30 ms 51964 KB Output is correct
19 Correct 28 ms 51916 KB Output is correct
20 Correct 621 ms 119616 KB Output is correct
21 Correct 551 ms 117860 KB Output is correct
22 Correct 662 ms 118316 KB Output is correct
23 Correct 571 ms 119728 KB Output is correct
24 Correct 156 ms 71316 KB Output is correct
25 Correct 110 ms 65288 KB Output is correct
26 Correct 113 ms 65332 KB Output is correct
27 Correct 683 ms 127484 KB Output is correct
28 Correct 681 ms 128320 KB Output is correct
29 Correct 785 ms 127680 KB Output is correct
30 Correct 765 ms 128232 KB Output is correct
31 Correct 29 ms 51916 KB Output is correct
32 Correct 74 ms 57292 KB Output is correct
33 Correct 117 ms 66496 KB Output is correct
34 Correct 538 ms 118496 KB Output is correct
35 Correct 32 ms 52684 KB Output is correct
36 Correct 50 ms 55928 KB Output is correct
37 Correct 74 ms 59868 KB Output is correct
38 Correct 359 ms 79808 KB Output is correct
39 Correct 460 ms 90464 KB Output is correct
40 Correct 607 ms 100972 KB Output is correct
41 Correct 781 ms 111540 KB Output is correct
42 Correct 874 ms 122092 KB Output is correct
43 Correct 29 ms 51916 KB Output is correct
44 Correct 28 ms 51912 KB Output is correct
45 Correct 28 ms 52044 KB Output is correct
46 Correct 29 ms 51924 KB Output is correct
47 Correct 29 ms 51976 KB Output is correct
48 Correct 29 ms 51940 KB Output is correct
49 Correct 29 ms 51916 KB Output is correct
50 Correct 28 ms 51944 KB Output is correct
51 Correct 28 ms 51984 KB Output is correct
52 Correct 29 ms 51848 KB Output is correct
53 Correct 29 ms 51924 KB Output is correct
54 Correct 29 ms 52032 KB Output is correct
55 Correct 30 ms 52200 KB Output is correct
56 Correct 525 ms 87220 KB Output is correct
57 Correct 786 ms 104108 KB Output is correct
58 Correct 777 ms 103904 KB Output is correct
59 Correct 28 ms 51844 KB Output is correct
60 Correct 29 ms 51980 KB Output is correct
61 Correct 28 ms 51916 KB Output is correct
62 Correct 1068 ms 131192 KB Output is correct
63 Correct 1044 ms 131080 KB Output is correct
64 Correct 1044 ms 130732 KB Output is correct
65 Correct 31 ms 52164 KB Output is correct
66 Correct 32 ms 52516 KB Output is correct
67 Correct 525 ms 86792 KB Output is correct
68 Correct 766 ms 104080 KB Output is correct
69 Correct 1098 ms 121792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
17 Correct 741 ms 130512 KB Output is correct
18 Correct 743 ms 130588 KB Output is correct
19 Correct 628 ms 167752 KB Output is correct
20 Correct 821 ms 149944 KB Output is correct
21 Correct 733 ms 128556 KB Output is correct
22 Correct 29 ms 51908 KB Output is correct
23 Correct 142 ms 63768 KB Output is correct
24 Correct 38 ms 53512 KB Output is correct
25 Correct 60 ms 57500 KB Output is correct
26 Correct 85 ms 61508 KB Output is correct
27 Correct 515 ms 90916 KB Output is correct
28 Correct 596 ms 101064 KB Output is correct
29 Correct 788 ms 110660 KB Output is correct
30 Correct 869 ms 119724 KB Output is correct
31 Correct 993 ms 129372 KB Output is correct
32 Correct 1220 ms 129488 KB Output is correct
33 Correct 1043 ms 131048 KB Output is correct
34 Correct 32 ms 52420 KB Output is correct
35 Correct 34 ms 52620 KB Output is correct
36 Correct 560 ms 88716 KB Output is correct
37 Correct 836 ms 107352 KB Output is correct
38 Correct 1236 ms 125892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 51916 KB Output is correct
2 Correct 33 ms 52004 KB Output is correct
3 Correct 29 ms 51912 KB Output is correct
4 Correct 29 ms 51892 KB Output is correct
5 Correct 28 ms 51872 KB Output is correct
6 Correct 29 ms 51940 KB Output is correct
7 Correct 29 ms 51972 KB Output is correct
8 Correct 28 ms 52048 KB Output is correct
9 Correct 554 ms 94624 KB Output is correct
10 Correct 62 ms 56516 KB Output is correct
11 Correct 272 ms 75036 KB Output is correct
12 Correct 82 ms 58564 KB Output is correct
13 Correct 42 ms 55568 KB Output is correct
14 Correct 31 ms 52044 KB Output is correct
15 Correct 33 ms 52116 KB Output is correct
16 Correct 532 ms 94680 KB Output is correct
17 Correct 28 ms 51916 KB Output is correct
18 Correct 29 ms 51976 KB Output is correct
19 Correct 29 ms 52000 KB Output is correct
20 Correct 29 ms 51940 KB Output is correct
21 Correct 30 ms 51908 KB Output is correct
22 Correct 29 ms 51916 KB Output is correct
23 Correct 1512 ms 134172 KB Output is correct
24 Correct 29 ms 51924 KB Output is correct
25 Correct 34 ms 52488 KB Output is correct
26 Correct 30 ms 52104 KB Output is correct
27 Correct 30 ms 52256 KB Output is correct
28 Correct 556 ms 84536 KB Output is correct
29 Correct 868 ms 101148 KB Output is correct
30 Correct 1199 ms 117300 KB Output is correct
31 Correct 1493 ms 134144 KB Output is correct
32 Correct 29 ms 51908 KB Output is correct
33 Correct 29 ms 51916 KB Output is correct
34 Correct 29 ms 51932 KB Output is correct
35 Correct 28 ms 51960 KB Output is correct
36 Correct 29 ms 51856 KB Output is correct
37 Correct 29 ms 51908 KB Output is correct
38 Correct 28 ms 51952 KB Output is correct
39 Correct 28 ms 51916 KB Output is correct
40 Correct 28 ms 51912 KB Output is correct
41 Correct 29 ms 51868 KB Output is correct
42 Correct 29 ms 51984 KB Output is correct
43 Correct 29 ms 52064 KB Output is correct
44 Correct 31 ms 52228 KB Output is correct
45 Correct 535 ms 87176 KB Output is correct
46 Correct 790 ms 104236 KB Output is correct
47 Correct 777 ms 104048 KB Output is correct
48 Correct 30 ms 51884 KB Output is correct
49 Correct 29 ms 51916 KB Output is correct
50 Correct 28 ms 51900 KB Output is correct
51 Correct 31 ms 51948 KB Output is correct
52 Correct 29 ms 51884 KB Output is correct
53 Correct 29 ms 51928 KB Output is correct
54 Correct 29 ms 51972 KB Output is correct
55 Incorrect 1410 ms 164168 KB Tree @(3, 5) appears more than once: for edges on positions 133337 and 133338
56 Halted 0 ms 0 KB -