제출 #317698

#제출 시각아이디문제언어결과실행 시간메모리
317698amunduzbaev슈퍼트리 잇기 (IOI20_supertrees)C++14
21 / 100
548 ms25208 KiB
//#include "grader.cpp"
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a) 
const int N=1005;
int used[N];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int> > b(n);
	bool ok1=0, ok2=0, ok0=0;
	for(int i=0;i<n;i++){
		b[i].resize(n);
		for(int j=0;j<n;j++){
			b[i][j]=0;
			if(p[i][j] == 1) ok1=1;
			else if(p[i][j] == 2) ok2=1;
			else ok0 = 1;
		}
	}
	if(ok1 && !ok2 && !ok0){
		for(int i=1;i<n;i++){
			b[0][i] = 1;
			b[i][0] = 1;
		}
		build(b);
		return 1;
	}
	
	else if((ok1 || ok0) && !ok2){
		vector<vector<int>> v(n);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(p[i][j] == 1 && i!=j){
					v[i].push_back(j);
				}
			}
			for(int j=0;j<v[i].size();j++){
				if(!p[v[i][j]][i]) return 0;
				for(int l=j;l<v[i].size();l++){
					if(!p[v[i][l]][v[i][j]]) return 0;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			for(int j=0;j<v[i].size();j++){
				used[v[i][j]] = 1;
				b[i][v[i][j]] = 1;
				b[v[i][j]][i] = 1;
			}
		}
		build(b);
		return 1;
	}
	else if((ok2 || ok0) && !ok1){
		vector<vector<int>> v(n);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				if(p[i][j] == 2 && i!=j)
					v[i].push_back(j);
			if(v[i].size() == 1) return 0;
			for(int j=0;j<v[i].size();j++){
				if(!p[v[i][j]][i]) return 0;
				for(int l=j+1;l<v[i].size();l++)
					if(!p[v[i][l]][v[i][j]]) return 0;
			}
		}
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			int j=0;
			b[i][v[i][j]] = 1;
			b[v[i][j]][i] = 1;
			for(;j<v[i].size() -1;j++){
				used[v[i][j]] = 1;
				b[v[i][j]][v[i][j+1]] = 1;
				b[v[i][j+1]][v[i][j]] = 1;
			}
			used[v[i][j]] = 1;
			b[i][v[i][j]] = 1;
			b[v[i][j]][i] = 1;
		}
		build(b);
		return 1;
	}
	if(ok0 || ok1 || ok2){
		vector<vector<int> > ones(n), twos(n);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j && p[i][j] == 1)
					ones[i].pb(j);
				if(i!=j && p[i][j] == 2)
					twos[i].pb(j);
			}
		}
		for(int i=0;i<n;i++){
			if(used[i])continue;
			for(int j=0;j<ones[i].size();j++){
				used[ones[i][j]] = 1;
				b[i][ones[i][j]] = 1;
				b[ones[i][j]][i] = 1;

			}
			int j=0, sz=twos[i].size();
			b[i][twos[i][j]] = 1;
			b[twos[i][j]][i] = 1;
			for(;j<sz-1; j++){
				used[twos[i][j]] = 1;
				b[twos[i][j]][twos[i][j+1]] = 1;
				b[twos[i][j+1]][twos[i][j]] = 1;
				//cout<<twos[i][j]<<" ";
			}
			used[twos[i][j]] = 1;
			b[i][twos[i][j]] = 1;
			b[twos[i][j]][i] = 1;

		}
		build(b);
		return 1;
	}
	return 0;
}
/*

5
0 2 2 2 2
2 0 2 2 2
2 2 0 2 2
2 2 2 0 2 
2 2 2 2 0

4
1 1 2 2 
1 1 2 2 
2 2 1 2 
2 2 2 1 

*/

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int l=j;l<v[i].size();l++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int l=j+1;l<v[i].size();l++)
      |                   ~^~~~~~~~~~~~
supertrees.cpp:75:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |    for(;j<v[i].size() -1;j++){
      |         ~^~~~~~~~~~~~~~~
supertrees.cpp:99:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |    for(int j=0;j<ones[i].size();j++){
      |                ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...