답안 #532420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532420 2022-03-02T21:29:44 Z Icebear16 분수 공원 (IOI21_parks) C++17
5 / 100
141 ms 23348 KB
//#include "parks.h"
//#include <bits/stdc++.h>
//int construct_roads(std::vector<int> x, std::vector<int> y) {
//    if (x.size() == 1) {
//	build({}, {}, {}, {});
//        return 1;
//    }else{
//	    std::vector<int> u, v, a, b;
//	    std::vector<std::pair<int,int>> A;
//	    for(int i=0;i<x.size();i++){
//	    	A.push_back(std::make_pair((x[i]+2*y[i]),i));
//		}
//		sort(A.begin(),A.end());
//		int r=x.size()-1;
//		int m=y[A[0].second];
//		int w=y[A[r].second];
//		int e=((w-m)/2)+1; 
//		std::vector<int> B(e,-1);
//		std::vector<int> C(e,-1);
//		for(int i=0;i<x.size();i++){
//			if(x[i]==2){
//				B[(y[i]-m)/2]=i;
//			}else{
//				C[(y[i]-m)/2]=i;
//			}
//		}
//		bool flag=true;
//	    for(int i=0;i<e;i++){
//	    	if(B[i]==-1 && C[i]==-1){
//	    		flag=false;
//	    		break;
//			}
//		}
//		if(flag==true){
//			for(int i=0;i<e;i++){
//				if(B[i]>=0 && C[i]>=0){
//			    	u.push_back(B[i]);
//			    	v.push_back(C[i]);
//				    a.push_back(3);
//			    	b.push_back((i*2)+m+1);
//				}
//				if(B[i]>=0 && B[i+1]>=0 && (i+1)!=e){
//			    	u.push_back(B[i]);
//			    	v.push_back(B[i+1]);
//				    a.push_back(1);
//			    	b.push_back((i*2)+m+1);
//				}
//				if(C[i]>=0 && C[i+1]>=0 && (i+1)!=e){
//			    	u.push_back(C[i]);
//			    	v.push_back(C[i+1]);
//				    a.push_back(5);
//			    	b.push_back((i*2)+m+1);
//				}
//			}
//		    build(u, v, a, b);
//		    return 1;
//		}else{
//			return 0;
//		}
//	}
//}
////4
////2 0
////2 2
////2 4
////2 6
//
////8
////4 8
////4 10
////2 6
////2 10
////2 4
////2 8
////4 4
////4 2



#include "parks.h"
#include <bits/stdc++.h>
int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }else{
	    std::vector<int> u, v, a, b;
	    std::vector<std::pair<int,int>> A;
	    for(int i=0;i<x.size();i++){
	    	A.push_back(std::make_pair((x[i]+2*y[i]),i));
		}
		sort(A.begin(),A.end());
		int r=x.size()-1;
		int m=y[A[0].second];
		int w=y[A[r].second];
		int e=((w-m)/2)+1; 
		std::vector<int> B(e,-1);
		std::vector<int> C(e,-1);
		for(int i=0;i<x.size();i++){
			if(x[i]==2){
				B[(y[i]-m)/2]=i;
			}else{
				C[(y[i]-m)/2]=i;
			}
		}
		bool flag=true;
	    for(int i=0;i<e;i++){
	    	if(B[i]==-1 && C[i]==-1){
	    		flag=false;
	    		break;
			}
		}
		if(flag==true){
			if(B[0]>=0 && C[0]>=0){
		    	u.push_back(B[0]);
		    	v.push_back(C[0]);
			    a.push_back(3);
		    	b.push_back(m+1);
			}
			for(int i=1;i<e;i++){
				if(B[i]>=0 && C[i]>=0){
			    	u.push_back(B[i]);
			    	v.push_back(C[i]);
				    a.push_back(3);
			    	b.push_back((i*2)+m+1);
				}
				if(B[i]>=0 && B[i-1]>=0){
			    	u.push_back(B[i]);
			    	v.push_back(B[i-1]);
				    a.push_back(1);
			    	b.push_back((i*2)+m-1);
				}
				if(C[i]>=0 && C[i-1]>=0){
			    	u.push_back(C[i]);
			    	v.push_back(C[i-1]);
				    a.push_back(5);
			    	b.push_back((i*2)+m-1);
				}
			}
		    build(u, v, a, b);
		    return 1;
		}else{
			return 0;
		}
	}
}
//4
//2 0
//2 2
//2 4
//2 6

//8
//4 8
//4 10
//2 6
//2 10
//2 4
//2 8
//4 4
//4 2

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |      for(int i=0;i<x.size();i++){
      |                  ~^~~~~~~~~
parks.cpp:99:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   for(int i=0;i<x.size();i++){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 141 ms 23320 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 428 KB Output is correct
26 Correct 1 ms 684 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 56 ms 9984 KB Output is correct
29 Correct 95 ms 13740 KB Output is correct
30 Correct 112 ms 20120 KB Output is correct
31 Correct 141 ms 23348 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 288 KB Output is correct
35 Incorrect 0 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 141 ms 23320 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 428 KB Output is correct
26 Correct 1 ms 684 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 56 ms 9984 KB Output is correct
29 Correct 95 ms 13740 KB Output is correct
30 Correct 112 ms 20120 KB Output is correct
31 Correct 141 ms 23348 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 288 KB Output is correct
35 Incorrect 0 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Incorrect 0 ms 204 KB Pair u[0]=1 @(200000, 4) and v[0]=2 @(199998, 2) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Incorrect 105 ms 15784 KB Pair u[0]=199575 @(2, 2) and v[0]=199999 @(62538, 2) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 56 ms 9744 KB Output is correct
10 Correct 5 ms 1260 KB Output is correct
11 Correct 26 ms 5212 KB Output is correct
12 Correct 8 ms 1740 KB Output is correct
13 Correct 8 ms 2032 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 55 ms 9708 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 141 ms 23320 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 428 KB Output is correct
26 Correct 1 ms 684 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 56 ms 9984 KB Output is correct
29 Correct 95 ms 13740 KB Output is correct
30 Correct 112 ms 20120 KB Output is correct
31 Correct 141 ms 23348 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 288 KB Output is correct
35 Incorrect 0 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
36 Halted 0 ms 0 KB -