답안 #439339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439339 2021-06-29T16:09:18 Z algorithm16 분수 공원 (IOI21_parks) C++17
15 / 100
300 ms 45932 KB
#include "parks.h"
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
vector <int> v[200005],u2,v2,a2,b2;
vector <pair<pair<int,int>,int> > v1;
bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b) {
	return a.first.second<b.first.second;
}
int bio[200005],cnt;
void dfs(int x) {
	bio[x]=1;
	cnt+=1;
	for(int i=0;i<v[x].size();i++) {
		if(!bio[v[x][i]]) dfs(v[x][i]);
	}
}
int construct_roads(std::vector<int> x,std::vector<int> y) {
	int n=x.size();
    if(n==1) {
		build({},{},{},{});
        return 1;
    }
    for(int i=0;i<n;i++) {
    	v1.push_back(make_pair(make_pair(x[i],y[i]),i));
	}
	sort(v1.begin(),v1.end(),comp);
	for(int i=0;i<v1.size();i++) {
		for(int j=i+1;j<v1.size() && j-i<=3;j++) {
			int x1=v1[i].first.first,y1=v1[i].first.second,x2=v1[j].first.first,y2=v1[j].first.second,i2=v1[i].second,j2=v1[j].second;
			if((abs(x1-x2)==2 && y1==y2) || (abs(y1-y2)==2 && x1==x2)) {
				v[i2].push_back(j2);
				v[j2].push_back(i2);
				u2.push_back(i2);
				v2.push_back(j2);
			}
		}
	}
    dfs(0);
    //cout << cnt << "\n";
    if(cnt<n) return 0;
    for(int i=0;i<u2.size();i++) {
    	if(y[u2[i]]==y[v2[i]]) {
    		a2.push_back(3);
    		b2.push_back(y[v2[i]]-1);
		}
		else if(x[u2[i]]==4) {
			a2.push_back(5);
			b2.push_back(y[v2[i]]-1);
		}
		else {
			a2.push_back(1);
			b2.push_back(y[v2[i]]-1);
		}
	}
	/*for(int i=0;i<u2.size();i++) {
		cout << u2[i] << " " << v2[i] << "\n";
	}
	cout << "\n";
	for(int i=0;i<a2.size();i++) {
		cout << a2[i] << " " << b2[i] << "\n";
	}*/
    build(u2,v2,a2,b2);
    return 1;
}

Compilation message

parks.cpp: In function 'void dfs(int)':
parks.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i=0;i<v[x].size();i++) {
      |              ~^~~~~~~~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i=0;i<v1.size();i++) {
      |              ~^~~~~~~~~~
parks.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int j=i+1;j<v1.size() && j-i<=3;j++) {
      |                 ~^~~~~~~~~~
parks.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0;i<u2.size();i++) {
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 5 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 296 ms 45920 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5196 KB Output is correct
27 Correct 6 ms 5324 KB Output is correct
28 Correct 109 ms 21420 KB Output is correct
29 Correct 164 ms 29708 KB Output is correct
30 Correct 233 ms 38004 KB Output is correct
31 Correct 300 ms 45932 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 4 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4988 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 6 ms 5196 KB Output is correct
45 Correct 114 ms 20524 KB Output is correct
46 Correct 164 ms 27488 KB Output is correct
47 Correct 168 ms 27076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 5 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 296 ms 45920 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5196 KB Output is correct
27 Correct 6 ms 5324 KB Output is correct
28 Correct 109 ms 21420 KB Output is correct
29 Correct 164 ms 29708 KB Output is correct
30 Correct 233 ms 38004 KB Output is correct
31 Correct 300 ms 45932 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 4 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4988 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 6 ms 5196 KB Output is correct
45 Correct 114 ms 20524 KB Output is correct
46 Correct 164 ms 27488 KB Output is correct
47 Correct 168 ms 27076 KB Output is correct
48 Incorrect 4 ms 4940 KB Tree (a[0], b[0]) = (3, 1) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2)
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
17 Incorrect 4 ms 4940 KB Tree (a[0], b[0]) = (3, 1) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=2 @(199998, 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
17 Incorrect 109 ms 14360 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 108 ms 22024 KB Output is correct
10 Correct 12 ms 6748 KB Output is correct
11 Correct 46 ms 14120 KB Output is correct
12 Correct 15 ms 7568 KB Output is correct
13 Correct 23 ms 9416 KB Output is correct
14 Correct 5 ms 5068 KB Output is correct
15 Correct 5 ms 5068 KB Output is correct
16 Correct 106 ms 20012 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 5 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 296 ms 45920 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5196 KB Output is correct
27 Correct 6 ms 5324 KB Output is correct
28 Correct 109 ms 21420 KB Output is correct
29 Correct 164 ms 29708 KB Output is correct
30 Correct 233 ms 38004 KB Output is correct
31 Correct 300 ms 45932 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 4 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4988 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 6 ms 5196 KB Output is correct
45 Correct 114 ms 20524 KB Output is correct
46 Correct 164 ms 27488 KB Output is correct
47 Correct 168 ms 27076 KB Output is correct
48 Incorrect 4 ms 4940 KB Tree (a[0], b[0]) = (3, 1) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2)
49 Halted 0 ms 0 KB -