답안 #447822

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447822 2021-07-27T15:45:57 Z mosiashvililuka 분수 공원 (IOI21_parks) C++17
30 / 100
188 ms 35376 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;
pair <int, int> p[200009],P[1000009];
vector <pair <int, int> > X[200009],Y[200009];
vector <int> U,V,A,B;
bool bo[9][200009];
int fx[9][200009];
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];
    	fx[p[i].first][p[i].second]=i;
	}
	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<=6; i+=2){
		sort(X[i].begin(),X[i].end());
		if(i==4) continue;
		e=X[i].size();
		for(j=0; j<e-1; j++){
			if(X[i][j].first+2<X[i][j+1].first) continue;
			c=X[i][j].second;d=X[i][j+1].second;
			U.push_back(c);V.push_back(d);
			if(i==2){
				A.push_back(i-1);B.push_back((p[c].second+p[d].second)/2);
			}else{
				A.push_back(i+1);B.push_back((p[c].second+p[d].second)/2);
			}
		}
	}
	i=4;e=X[i].size();cc=0;
	for(j=0; j<e-1; j++){
		if(X[i][j].first+2<X[i][j+1].first){
			cc=0;
			continue;
		}
		c=X[i][j].second;d=X[i][j+1].second;
		U.push_back(c);V.push_back(d);
		if(cc==0){
			A.push_back(i+1);B.push_back((p[c].second+p[d].second)/2);
		}else{
			A.push_back(i-1);B.push_back((p[c].second+p[d].second)/2);
		}
		cc^=1;
	}
	for(i=0; i<A.size(); i++){
		bo[A[i]][B[i]]=1;
	}
	for(j=2; j<=200000; j++){
		if(fx[2][j]==0||fx[4][j]==0) continue;
		if(bo[3][j-1]==0){
			bo[3][j-1]=1;
			U.push_back(fx[2][j]);V.push_back(fx[4][j]);
			A.push_back(3);B.push_back(j-1);
			continue;
		}
		if(bo[3][j+1]==0){
			bo[3][j+1]=1;
			U.push_back(fx[2][j]);V.push_back(fx[4][j]);
			A.push_back(3);B.push_back(j+1);
			continue;
		}
	}
	for(j=2; j<=200000; j++){
		if(fx[4][j]==0||fx[6][j]==0) continue;
		if(bo[5][j-1]==0){
			bo[5][j-1]=1;
			U.push_back(fx[4][j]);V.push_back(fx[6][j]);
			A.push_back(5);B.push_back(j-1);
			continue;
		}
		if(bo[5][j+1]==0){
			bo[5][j+1]=1;
			U.push_back(fx[4][j]);V.push_back(fx[6][j]);
			A.push_back(5);B.push_back(j+1);
			continue;
		}
	}
	/*cout<<U.size()<<endl;
	for(i=0; i<U.size(); i++){
		cout<<U[i]<<" "<<V[i]<<" "<<A[i]<<" "<<B[i]<<endl;
	}*/
	for(i=0; i<U.size(); i++){
		PI++;P[PI].first=U[i];P[PI].second=V[i];
	}
	if(check()==0){
		return 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:16:44: warning: self-comparison always evaluates to false [-Wtautological-compare]
   16 |  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:67:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(i=0; i<A.size(); i++){
      |           ~^~~~~~~~~
parks.cpp:104:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |  for(i=0; i<U.size(); i++){
      |           ~^~~~~~~~~
parks.cpp:111:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |  for(i=0; i<U.size(); i++){
      |           ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
17 Correct 7 ms 9740 KB Output is correct
18 Correct 7 ms 9692 KB Output is correct
19 Correct 7 ms 9676 KB Output is correct
20 Correct 7 ms 9676 KB Output is correct
21 Correct 7 ms 9676 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 173 ms 34080 KB Output is correct
24 Correct 7 ms 9676 KB Output is correct
25 Correct 8 ms 9932 KB Output is correct
26 Correct 8 ms 10060 KB Output is correct
27 Correct 9 ms 10244 KB Output is correct
28 Correct 71 ms 19708 KB Output is correct
29 Correct 128 ms 23936 KB Output is correct
30 Correct 137 ms 29824 KB Output is correct
31 Correct 188 ms 34068 KB Output is correct
32 Correct 9 ms 9676 KB Output is correct
33 Correct 7 ms 9700 KB Output is correct
34 Correct 7 ms 9676 KB Output is correct
35 Correct 7 ms 9616 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
37 Correct 7 ms 9804 KB Output is correct
38 Correct 8 ms 9708 KB Output is correct
39 Correct 8 ms 9744 KB Output is correct
40 Correct 8 ms 9676 KB Output is correct
41 Correct 8 ms 9676 KB Output is correct
42 Correct 8 ms 9704 KB Output is correct
43 Correct 8 ms 9932 KB Output is correct
44 Correct 9 ms 10100 KB Output is correct
45 Correct 80 ms 21476 KB Output is correct
46 Correct 118 ms 27188 KB Output is correct
47 Correct 118 ms 27128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
17 Correct 7 ms 9740 KB Output is correct
18 Correct 7 ms 9692 KB Output is correct
19 Correct 7 ms 9676 KB Output is correct
20 Correct 7 ms 9676 KB Output is correct
21 Correct 7 ms 9676 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 173 ms 34080 KB Output is correct
24 Correct 7 ms 9676 KB Output is correct
25 Correct 8 ms 9932 KB Output is correct
26 Correct 8 ms 10060 KB Output is correct
27 Correct 9 ms 10244 KB Output is correct
28 Correct 71 ms 19708 KB Output is correct
29 Correct 128 ms 23936 KB Output is correct
30 Correct 137 ms 29824 KB Output is correct
31 Correct 188 ms 34068 KB Output is correct
32 Correct 9 ms 9676 KB Output is correct
33 Correct 7 ms 9700 KB Output is correct
34 Correct 7 ms 9676 KB Output is correct
35 Correct 7 ms 9616 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
37 Correct 7 ms 9804 KB Output is correct
38 Correct 8 ms 9708 KB Output is correct
39 Correct 8 ms 9744 KB Output is correct
40 Correct 8 ms 9676 KB Output is correct
41 Correct 8 ms 9676 KB Output is correct
42 Correct 8 ms 9704 KB Output is correct
43 Correct 8 ms 9932 KB Output is correct
44 Correct 9 ms 10100 KB Output is correct
45 Correct 80 ms 21476 KB Output is correct
46 Correct 118 ms 27188 KB Output is correct
47 Correct 118 ms 27128 KB Output is correct
48 Correct 8 ms 9728 KB Output is correct
49 Correct 7 ms 9700 KB Output is correct
50 Correct 7 ms 9668 KB Output is correct
51 Correct 7 ms 9704 KB Output is correct
52 Correct 8 ms 9676 KB Output is correct
53 Correct 8 ms 9708 KB Output is correct
54 Correct 8 ms 9704 KB Output is correct
55 Correct 184 ms 34012 KB Output is correct
56 Correct 7 ms 9748 KB Output is correct
57 Correct 9 ms 10060 KB Output is correct
58 Correct 12 ms 10608 KB Output is correct
59 Correct 11 ms 10828 KB Output is correct
60 Correct 92 ms 22508 KB Output is correct
61 Correct 120 ms 26980 KB Output is correct
62 Correct 149 ms 30936 KB Output is correct
63 Correct 182 ms 35376 KB Output is correct
64 Correct 8 ms 9676 KB Output is correct
65 Correct 7 ms 9704 KB Output is correct
66 Correct 8 ms 9676 KB Output is correct
67 Correct 151 ms 32340 KB Output is correct
68 Correct 158 ms 32420 KB Output is correct
69 Correct 156 ms 32284 KB Output is correct
70 Correct 9 ms 10060 KB Output is correct
71 Correct 10 ms 10612 KB Output is correct
72 Correct 78 ms 21952 KB Output is correct
73 Correct 117 ms 27616 KB Output is correct
74 Correct 155 ms 34268 KB Output is correct
75 Correct 170 ms 35080 KB Output is correct
76 Correct 153 ms 32340 KB Output is correct
77 Correct 9 ms 10316 KB Output is correct
78 Correct 10 ms 10700 KB Output is correct
79 Correct 81 ms 22208 KB Output is correct
80 Correct 125 ms 28364 KB Output is correct
81 Correct 163 ms 35220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
17 Runtime error 15 ms 19424 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
17 Runtime error 61 ms 26124 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9800 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9700 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 9 ms 9676 KB Output is correct
6 Correct 8 ms 9676 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 77 ms 21544 KB Output is correct
10 Correct 14 ms 11000 KB Output is correct
11 Correct 40 ms 16088 KB Output is correct
12 Correct 16 ms 11596 KB Output is correct
13 Correct 19 ms 13740 KB Output is correct
14 Correct 8 ms 9804 KB Output is correct
15 Correct 8 ms 9932 KB Output is correct
16 Correct 89 ms 21588 KB Output is correct
17 Correct 7 ms 9740 KB Output is correct
18 Correct 7 ms 9692 KB Output is correct
19 Correct 7 ms 9676 KB Output is correct
20 Correct 7 ms 9676 KB Output is correct
21 Correct 7 ms 9676 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 173 ms 34080 KB Output is correct
24 Correct 7 ms 9676 KB Output is correct
25 Correct 8 ms 9932 KB Output is correct
26 Correct 8 ms 10060 KB Output is correct
27 Correct 9 ms 10244 KB Output is correct
28 Correct 71 ms 19708 KB Output is correct
29 Correct 128 ms 23936 KB Output is correct
30 Correct 137 ms 29824 KB Output is correct
31 Correct 188 ms 34068 KB Output is correct
32 Correct 9 ms 9676 KB Output is correct
33 Correct 7 ms 9700 KB Output is correct
34 Correct 7 ms 9676 KB Output is correct
35 Correct 7 ms 9616 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
37 Correct 7 ms 9804 KB Output is correct
38 Correct 8 ms 9708 KB Output is correct
39 Correct 8 ms 9744 KB Output is correct
40 Correct 8 ms 9676 KB Output is correct
41 Correct 8 ms 9676 KB Output is correct
42 Correct 8 ms 9704 KB Output is correct
43 Correct 8 ms 9932 KB Output is correct
44 Correct 9 ms 10100 KB Output is correct
45 Correct 80 ms 21476 KB Output is correct
46 Correct 118 ms 27188 KB Output is correct
47 Correct 118 ms 27128 KB Output is correct
48 Correct 8 ms 9728 KB Output is correct
49 Correct 7 ms 9700 KB Output is correct
50 Correct 7 ms 9668 KB Output is correct
51 Correct 7 ms 9704 KB Output is correct
52 Correct 8 ms 9676 KB Output is correct
53 Correct 8 ms 9708 KB Output is correct
54 Correct 8 ms 9704 KB Output is correct
55 Correct 184 ms 34012 KB Output is correct
56 Correct 7 ms 9748 KB Output is correct
57 Correct 9 ms 10060 KB Output is correct
58 Correct 12 ms 10608 KB Output is correct
59 Correct 11 ms 10828 KB Output is correct
60 Correct 92 ms 22508 KB Output is correct
61 Correct 120 ms 26980 KB Output is correct
62 Correct 149 ms 30936 KB Output is correct
63 Correct 182 ms 35376 KB Output is correct
64 Correct 8 ms 9676 KB Output is correct
65 Correct 7 ms 9704 KB Output is correct
66 Correct 8 ms 9676 KB Output is correct
67 Correct 151 ms 32340 KB Output is correct
68 Correct 158 ms 32420 KB Output is correct
69 Correct 156 ms 32284 KB Output is correct
70 Correct 9 ms 10060 KB Output is correct
71 Correct 10 ms 10612 KB Output is correct
72 Correct 78 ms 21952 KB Output is correct
73 Correct 117 ms 27616 KB Output is correct
74 Correct 155 ms 34268 KB Output is correct
75 Correct 170 ms 35080 KB Output is correct
76 Correct 153 ms 32340 KB Output is correct
77 Correct 9 ms 10316 KB Output is correct
78 Correct 10 ms 10700 KB Output is correct
79 Correct 81 ms 22208 KB Output is correct
80 Correct 125 ms 28364 KB Output is correct
81 Correct 163 ms 35220 KB Output is correct
82 Runtime error 15 ms 19424 KB Execution killed with signal 11
83 Halted 0 ms 0 KB -