답안 #532440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532440 2022-03-02T21:48:42 Z Icebear16 분수 공원 (IOI21_parks) C++17
0 / 100
0 ms 204 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){
			bool temp=false;
			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 && C[i]==1) || (B[i]==1 && C[i]==0)){
			    		temp=true;
					}
				}
				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((B[i]==0 && B[i+1]==1) || (B[i]==1 && B[i+1]==0)){
			    		temp=true;
					}
				}
				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);
			    	if((C[i]==0 && C[i+1]==1) || (C[i]==1 && C[i+1]==0)){
			    		temp=true;
					}
				}
			}
			if(abs(x[0]-x[1])+abs(y[0]-y[1])==2){
				if(x[0]==x[1]){
					u.push_back(0);
			    	v.push_back(1);
			    	if(x[0]==2){
			    		a.push_back(1);
					}else{
				    	a.push_back(5);
					}
			    	b.push_back((y[0]+y[1])/2);
				}else{
					u.push_back(0);
			    	v.push_back(1);
				    a.push_back(3);
			    	b.push_back(y[0]+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:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |      for(int i=0;i<x.size();i++){
      |                  ~^~~~~~~~~
parks.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int i=0;i<x.size();i++){
      |               ~^~~~~~~~~
parks.cpp:35:9: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
   35 |    bool temp=false;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Edge between 0 and 1 appears more than once: appeared on positions 0 and 1
3 Halted 0 ms 0 KB -