답안 #759297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759297 2023-06-16T04:39:37 Z Piokemon 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
185 ms 24124 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

bool odw[1009];
int nr[1009];
vector<int> lista[1009];
int incykl[1009];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<int> czesc(n,0);
	vector<vector<int>> answer(n,czesc);
	for(int i=0;i<=n;i++) odw[i]=0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (p[i][j]==3) return 0;
		}
	}
	for (int i=0;i<n;i++){
		if (odw[i]) continue;
		nr[i] = i;
		lista[i].push_back(i);
		odw[i] = 1;
		for (int j=0;j<n;j++){
			if (odw[j] || i==j) continue;
			if (p[i][j]==1){
				answer[i][j] = 1;
				answer[j][i] = 1;
				nr[j] = i;
				lista[i].push_back(j);
				odw[j] = 1;
			}
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (p[i][j] != p[nr[i]][j]) return 0;
		}
	}
	for(int i=0;i<=n;i++) odw[i]=0;

	/*cout << "nr: ";
	for (int i=0;i<n;i++) cout << nr[i] << ' ';
	cout << '\n';*/
	for (int i=0;i<n;i++){
		if (nr[i]!=i || odw[i]) continue;
		vector<int> cykl;
		cykl.push_back(i);
		odw[i] = 1;
		for (int j=0;j<n;j++){
			if (p[i][j]==2 && !odw[nr[j]]){
				cykl.push_back(nr[j]);
				odw[nr[j]] = 1;
			}
		}
		
		for (int j=0;j<=n;j++) incykl[j] = 0;
		for (int j:cykl) incykl[j] = 1; 

		for (int j:cykl){
			for (int k=0;k<n;k++){
				if (nr[k]==j){
					if (p[k][j] != 1) return 0;
				}
				else if (incykl[nr[k]]){
					if (p[k][j] != 2) return 0;
				}
				else{
					if (p[k][j] != 0) return 0;
				}
			}
		}

		/*cout << "cykl: ";
		for (int j:cykl){
			cout << j << ' ';
		}
		cout << '\n';*/
		if (cykl.size()==2) return 0;
		if (cykl.size()==1) continue;
		for (int j=0;j<cykl.size()-1;j++){
			answer[cykl[j]][cykl[j+1]] = 1;
			answer[cykl[j+1]][cykl[j]] = 1;
		}
		answer[cykl.back()][cykl[0]] = 1;
		answer[cykl[0]][cykl.back()] =1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for (int j=0;j<cykl.size()-1;j++){
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1260 KB Output is correct
7 Correct 152 ms 22180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1260 KB Output is correct
7 Correct 152 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 156 ms 22208 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 68 ms 12192 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 5836 KB Output is correct
21 Correct 152 ms 22204 KB Output is correct
22 Correct 152 ms 22212 KB Output is correct
23 Correct 152 ms 22164 KB Output is correct
24 Correct 163 ms 22132 KB Output is correct
25 Correct 66 ms 12204 KB Output is correct
26 Correct 66 ms 12296 KB Output is correct
27 Correct 152 ms 22216 KB Output is correct
28 Correct 158 ms 22280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 155 ms 24008 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 170 ms 23972 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 84 ms 14108 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 39 ms 6220 KB Output is correct
22 Correct 155 ms 24012 KB Output is correct
23 Correct 154 ms 24124 KB Output is correct
24 Correct 160 ms 23972 KB Output is correct
25 Correct 70 ms 14116 KB Output is correct
26 Correct 68 ms 14096 KB Output is correct
27 Correct 161 ms 24028 KB Output is correct
28 Correct 156 ms 24064 KB Output is correct
29 Correct 69 ms 14096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 38 ms 5836 KB Output is correct
5 Correct 185 ms 22196 KB Output is correct
6 Correct 157 ms 22232 KB Output is correct
7 Correct 155 ms 22128 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 5808 KB Output is correct
10 Correct 158 ms 22384 KB Output is correct
11 Correct 158 ms 22148 KB Output is correct
12 Correct 159 ms 22188 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 40 ms 5820 KB Output is correct
17 Correct 152 ms 22160 KB Output is correct
18 Correct 153 ms 22232 KB Output is correct
19 Correct 167 ms 22220 KB Output is correct
20 Correct 160 ms 22188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1260 KB Output is correct
7 Correct 152 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 156 ms 22208 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 68 ms 12192 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 5836 KB Output is correct
21 Correct 152 ms 22204 KB Output is correct
22 Correct 152 ms 22212 KB Output is correct
23 Correct 152 ms 22164 KB Output is correct
24 Correct 163 ms 22132 KB Output is correct
25 Correct 66 ms 12204 KB Output is correct
26 Correct 66 ms 12296 KB Output is correct
27 Correct 152 ms 22216 KB Output is correct
28 Correct 158 ms 22280 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 155 ms 24008 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 7 ms 1216 KB Output is correct
41 Correct 170 ms 23972 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 4 ms 856 KB Output is correct
45 Correct 84 ms 14108 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 328 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 39 ms 6220 KB Output is correct
50 Correct 155 ms 24012 KB Output is correct
51 Correct 154 ms 24124 KB Output is correct
52 Correct 160 ms 23972 KB Output is correct
53 Correct 70 ms 14116 KB Output is correct
54 Correct 68 ms 14096 KB Output is correct
55 Correct 161 ms 24028 KB Output is correct
56 Correct 156 ms 24064 KB Output is correct
57 Correct 69 ms 14096 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 68 ms 14108 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 39 ms 6296 KB Output is correct
66 Correct 67 ms 14100 KB Output is correct
67 Correct 65 ms 14112 KB Output is correct
68 Correct 65 ms 14096 KB Output is correct
69 Correct 67 ms 14108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1260 KB Output is correct
7 Correct 152 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 156 ms 22208 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 68 ms 12192 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 5836 KB Output is correct
21 Correct 152 ms 22204 KB Output is correct
22 Correct 152 ms 22212 KB Output is correct
23 Correct 152 ms 22164 KB Output is correct
24 Correct 163 ms 22132 KB Output is correct
25 Correct 66 ms 12204 KB Output is correct
26 Correct 66 ms 12296 KB Output is correct
27 Correct 152 ms 22216 KB Output is correct
28 Correct 158 ms 22280 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 155 ms 24008 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 7 ms 1216 KB Output is correct
41 Correct 170 ms 23972 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 4 ms 856 KB Output is correct
45 Correct 84 ms 14108 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 328 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 39 ms 6220 KB Output is correct
50 Correct 155 ms 24012 KB Output is correct
51 Correct 154 ms 24124 KB Output is correct
52 Correct 160 ms 23972 KB Output is correct
53 Correct 70 ms 14116 KB Output is correct
54 Correct 68 ms 14096 KB Output is correct
55 Correct 161 ms 24028 KB Output is correct
56 Correct 156 ms 24064 KB Output is correct
57 Correct 69 ms 14096 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 38 ms 5836 KB Output is correct
62 Correct 185 ms 22196 KB Output is correct
63 Correct 157 ms 22232 KB Output is correct
64 Correct 155 ms 22128 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 39 ms 5808 KB Output is correct
67 Correct 158 ms 22384 KB Output is correct
68 Correct 158 ms 22148 KB Output is correct
69 Correct 159 ms 22188 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 40 ms 5820 KB Output is correct
74 Correct 152 ms 22160 KB Output is correct
75 Correct 153 ms 22232 KB Output is correct
76 Correct 167 ms 22220 KB Output is correct
77 Correct 160 ms 22188 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 68 ms 14108 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 39 ms 6296 KB Output is correct
86 Correct 67 ms 14100 KB Output is correct
87 Correct 65 ms 14112 KB Output is correct
88 Correct 65 ms 14096 KB Output is correct
89 Correct 67 ms 14108 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 328 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 66 ms 14096 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 336 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 16 ms 3732 KB Output is correct
98 Correct 65 ms 14028 KB Output is correct
99 Correct 80 ms 14020 KB Output is correct
100 Correct 64 ms 14108 KB Output is correct
101 Correct 64 ms 14024 KB Output is correct
102 Correct 68 ms 14096 KB Output is correct
103 Correct 65 ms 14112 KB Output is correct
104 Correct 64 ms 14012 KB Output is correct
105 Correct 67 ms 14116 KB Output is correct