답안 #384740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384740 2021-04-02T06:50:35 Z nicholask 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
264 ms 22380 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
int construct(vector <vector <int> > p){
	int n=p.size();
	vector <vector <int> > ans(n,vector<int>(n,0));
	vector <pair <int,vector <int> > > ones;
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (p[i][j]==3) return 0;
		}
	}
	bool d[n];
	int cnt=0;
	int belong[n];
	for (int i=0; i<n; i++) d[i]=0;
	for (int i=0; i<n; i++){
		if (d[i]) continue;
		vector <int> v;
		for (int j=i; j<n; j++){
			if (p[i][j]==1){
				if (d[j]) return 0;
				d[j]=1;
				v.push_back(j);
			}
		}
		for (int j=0; j<v.size()-1; j++) ans[v[j]][v[j+1]]=1;
		ones.push_back({cnt,v});
		for (auto&j:v) belong[j]=cnt;
		cnt++;
	}
	cnt=0;
	int bigbelong[n];
	for (int i=0; i<n; i++) bigbelong[i]=0;
	int nway[n];
	for (int i=0; i<n; i++) nway[i]=0;
	bool e[ones.size()];
	for (int i=0; i<ones.size(); i++) e[i]=0;
	for (int i=0; i<ones.size(); i++){
		if (e[i]) continue;
		vector <int> temp;
		temp.push_back(ones[i].y.front());
		for (auto&j:ones[i].y) bigbelong[j]=cnt;
		for (int j=i+1; j<ones.size(); j++){
			if (!e[j]&&p[ones[i].y.front()][ones[j].y.front()]==2){
				temp.push_back(ones[j].y.front());
				for (auto&k:ones[j].y) bigbelong[k]=cnt;
				e[j]=1;
			}
		}
		int ss=temp.size();
		if (ss<3){
			nway[cnt]=1;
			cnt++;
			continue;
		}
		for (int j=0; j<temp.size(); j++) ans[temp[j]][temp[(j+1)%ss]]=1;
		nway[cnt]=2;
		cnt++;
	}
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			if (p[i][j]==0){
				if (bigbelong[i]==bigbelong[j]) return 0;
			} else if (p[i][j]==1){
				if (belong[i]!=belong[j]&&(bigbelong[i]!=bigbelong[j]||nway[bigbelong[i]]!=1)) return 0;
			} else if (p[i][j]==2){
				if (belong[i]==belong[j]||bigbelong[i]!=bigbelong[j]||nway[bigbelong[i]]!=2) return 0;
			}
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (ans[j][i]) ans[i][j]=1; 
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int j=0; j<v.size()-1; j++) ans[v[j]][v[j+1]]=1;
      |                 ~^~~~~~~~~~~
supertrees.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i=0; i<ones.size(); i++) e[i]=0;
      |                ~^~~~~~~~~~~~
supertrees.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<ones.size(); i++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for (int j=i+1; j<ones.size(); j++){
      |                   ~^~~~~~~~~~~~
supertrees.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int j=0; j<temp.size(); j++) ans[temp[j]][temp[(j+1)%ss]]=1;
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 1260 KB Output is correct
7 Correct 239 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 1260 KB Output is correct
7 Correct 239 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 247 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 107 ms 12128 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 62 ms 5884 KB Output is correct
21 Correct 250 ms 22252 KB Output is correct
22 Correct 247 ms 22252 KB Output is correct
23 Correct 250 ms 22124 KB Output is correct
24 Correct 247 ms 22124 KB Output is correct
25 Correct 99 ms 12140 KB Output is correct
26 Correct 101 ms 12140 KB Output is correct
27 Correct 249 ms 22252 KB Output is correct
28 Correct 250 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 11 ms 1260 KB Output is correct
9 Correct 253 ms 22124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 239 ms 22380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 106 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 71 ms 5816 KB Output is correct
22 Correct 264 ms 22124 KB Output is correct
23 Correct 260 ms 22124 KB Output is correct
24 Correct 250 ms 22172 KB Output is correct
25 Correct 103 ms 12268 KB Output is correct
26 Correct 101 ms 12268 KB Output is correct
27 Correct 250 ms 22252 KB Output is correct
28 Correct 252 ms 22152 KB Output is correct
29 Correct 102 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 63 ms 5868 KB Output is correct
5 Correct 247 ms 22124 KB Output is correct
6 Correct 254 ms 22124 KB Output is correct
7 Correct 250 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 63 ms 5996 KB Output is correct
10 Correct 249 ms 22252 KB Output is correct
11 Correct 246 ms 22124 KB Output is correct
12 Correct 250 ms 22184 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 63 ms 5868 KB Output is correct
17 Correct 248 ms 22252 KB Output is correct
18 Correct 247 ms 22272 KB Output is correct
19 Correct 244 ms 22124 KB Output is correct
20 Correct 247 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 1260 KB Output is correct
7 Correct 239 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 247 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 107 ms 12128 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 62 ms 5884 KB Output is correct
21 Correct 250 ms 22252 KB Output is correct
22 Correct 247 ms 22252 KB Output is correct
23 Correct 250 ms 22124 KB Output is correct
24 Correct 247 ms 22124 KB Output is correct
25 Correct 99 ms 12140 KB Output is correct
26 Correct 101 ms 12140 KB Output is correct
27 Correct 249 ms 22252 KB Output is correct
28 Correct 250 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 253 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 239 ms 22380 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 106 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 71 ms 5816 KB Output is correct
50 Correct 264 ms 22124 KB Output is correct
51 Correct 260 ms 22124 KB Output is correct
52 Correct 250 ms 22172 KB Output is correct
53 Correct 103 ms 12268 KB Output is correct
54 Correct 101 ms 12268 KB Output is correct
55 Correct 250 ms 22252 KB Output is correct
56 Correct 252 ms 22152 KB Output is correct
57 Correct 102 ms 12268 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 892 KB Output is correct
61 Correct 103 ms 12140 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 2 ms 364 KB Output is correct
65 Correct 63 ms 5868 KB Output is correct
66 Correct 100 ms 12268 KB Output is correct
67 Correct 101 ms 12268 KB Output is correct
68 Correct 100 ms 12268 KB Output is correct
69 Correct 100 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 1260 KB Output is correct
7 Correct 239 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 247 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 107 ms 12128 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 62 ms 5884 KB Output is correct
21 Correct 250 ms 22252 KB Output is correct
22 Correct 247 ms 22252 KB Output is correct
23 Correct 250 ms 22124 KB Output is correct
24 Correct 247 ms 22124 KB Output is correct
25 Correct 99 ms 12140 KB Output is correct
26 Correct 101 ms 12140 KB Output is correct
27 Correct 249 ms 22252 KB Output is correct
28 Correct 250 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 253 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 239 ms 22380 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 106 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 71 ms 5816 KB Output is correct
50 Correct 264 ms 22124 KB Output is correct
51 Correct 260 ms 22124 KB Output is correct
52 Correct 250 ms 22172 KB Output is correct
53 Correct 103 ms 12268 KB Output is correct
54 Correct 101 ms 12268 KB Output is correct
55 Correct 250 ms 22252 KB Output is correct
56 Correct 252 ms 22152 KB Output is correct
57 Correct 102 ms 12268 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 63 ms 5868 KB Output is correct
62 Correct 247 ms 22124 KB Output is correct
63 Correct 254 ms 22124 KB Output is correct
64 Correct 250 ms 22124 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 63 ms 5996 KB Output is correct
67 Correct 249 ms 22252 KB Output is correct
68 Correct 246 ms 22124 KB Output is correct
69 Correct 250 ms 22184 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 63 ms 5868 KB Output is correct
74 Correct 248 ms 22252 KB Output is correct
75 Correct 247 ms 22272 KB Output is correct
76 Correct 244 ms 22124 KB Output is correct
77 Correct 247 ms 22124 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 892 KB Output is correct
81 Correct 103 ms 12140 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 2 ms 364 KB Output is correct
85 Correct 63 ms 5868 KB Output is correct
86 Correct 100 ms 12268 KB Output is correct
87 Correct 101 ms 12268 KB Output is correct
88 Correct 100 ms 12268 KB Output is correct
89 Correct 100 ms 12268 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 748 KB Output is correct
93 Correct 99 ms 12140 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 3820 KB Output is correct
98 Correct 99 ms 14060 KB Output is correct
99 Correct 100 ms 14060 KB Output is correct
100 Correct 99 ms 14080 KB Output is correct
101 Correct 98 ms 14188 KB Output is correct
102 Correct 91 ms 14060 KB Output is correct
103 Correct 92 ms 14060 KB Output is correct
104 Correct 93 ms 14188 KB Output is correct
105 Correct 102 ms 14060 KB Output is correct