답안 #831964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831964 2023-08-20T18:39:04 Z gesgha 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
188 ms 24020 KB
#include "supertrees.h"
#include <bits/stdc++.h>
 
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
 
#define fi first
#define se second
#define pb push_back
 
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
 
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ve = vector <T>;
 
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
 
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
 
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
 
const int oo = 1e9;
const ll OO = 1e18;
const int N = 1e6 + 10;
const int M = 3e3 + 100;
const int mod = 1e9 + 7;
const bool TEST = 1;

int cnt[M][4];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cnt[i][p[i][j]]++;
			if(p[i][j] == 3) return 0;
		}
	}
	ve <bool> vis(n, 0);
	for (int i = 0; i < n; i++) {
		if (vis[i]) continue;
		ve <int> ids;
		bool w2 = 0;
		for (int j = 0; j < n; j++) if (p[i][j]) {
			ids.pb(j);
			if (vis[j]) return 0;
			w2 |= (p[i][j] == 2);
		}
		for (int i = 0; i < sz(ids); i++) {
			for (int j = 0; j < sz(ids); j++) if (!p[ids[i]][ids[j]]) return 0;
		}
		if (w2) {
			ve <ve <int>> palki;
			ve <bool> used(n);
			for (auto x : ids) {
				if (used[x]) continue;
				ve <int> palka;
				for (int j = 0; j < n; j++) {
					if (p[x][j] == 1) {
						palka.pb(j);
						if (used[j]) return 0;
					}
				}
				palki.pb(palka);
				for (int j = 0; j < sz(palka); j++) used[palka[j]] = 1;
				for (int i = 0; i < sz(palka) - 1; i++) {
					answer[palka[i]][palka[i + 1]] = 1;
					answer[palka[i + 1]][palka[i]] = 1;
				}
			}
			for (int i = 0; i < sz(palki); i++) {
				for (auto x : palki[i]) {
					if (cnt[x][1] != sz(palki[i])) return 0;
					if (cnt[x][0] != n - sz(ids)) return 0;
					if (cnt[x][2] != sz(ids) - sz(palki[i]))return 0;
					for (auto y : palki[i]) if (p[x][y] != 1) return 0;
				}
			}
			for (int i = 0; i < sz(palki) - 1; i++) {
				answer[palki[i][0]][palki[i + 1][0]] = 1;
				answer[palki[i + 1][0]][palki[i][0]] = 1;
			}
			if (sz(ids) <= 2) return 0;
			answer[palki[0][0]][palki[sz(palki) - 1][0]] = 1;
			answer[palki[sz(palki) - 1][0]][palki[0][0]] = 1;
			
		} else {
			for (int i = 0; i < sz(ids); i++) {
				if (cnt[ids[i]][1] != sz(ids)) return 0;
				if (cnt[ids[i]][0] != n - sz(ids)) return 0;
				for (int j = 0; j < sz(ids); j++) if (p[ids[i]][ids[j]] != 1) return 0;
			}
			for (int i = 0; i < sz(ids) - 1; i++) {
				answer[ids[i]][ids[i + 1]] = 1;
				answer[ids[i + 1]][ids[i]] = 1;
			}
		}
		for (auto x : ids) vis[x] = 1;
	}
	for (int i = 0; i < n; i++) answer[i][i] = 0;
	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23924 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 151 ms 23932 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 64 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6216 KB Output is correct
21 Correct 151 ms 23984 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 158 ms 23928 KB Output is correct
24 Correct 151 ms 23936 KB Output is correct
25 Correct 63 ms 14056 KB Output is correct
26 Correct 77 ms 14056 KB Output is correct
27 Correct 154 ms 23940 KB Output is correct
28 Correct 151 ms 23940 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 1 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 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 6 ms 1260 KB Output is correct
9 Correct 151 ms 23980 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 228 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 153 ms 23988 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 64 ms 14068 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 40 ms 6256 KB Output is correct
22 Correct 177 ms 23928 KB Output is correct
23 Correct 160 ms 24008 KB Output is correct
24 Correct 161 ms 23956 KB Output is correct
25 Correct 68 ms 14084 KB Output is correct
26 Correct 63 ms 14076 KB Output is correct
27 Correct 153 ms 23928 KB Output is correct
28 Correct 155 ms 24012 KB Output is correct
29 Correct 64 ms 14116 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 304 KB Output is correct
4 Correct 38 ms 6256 KB Output is correct
5 Correct 150 ms 24012 KB Output is correct
6 Correct 172 ms 24020 KB Output is correct
7 Correct 155 ms 23968 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 6216 KB Output is correct
10 Correct 154 ms 23940 KB Output is correct
11 Correct 154 ms 23996 KB Output is correct
12 Correct 155 ms 23940 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 39 ms 6248 KB Output is correct
17 Correct 154 ms 23940 KB Output is correct
18 Correct 188 ms 23928 KB Output is correct
19 Correct 153 ms 24000 KB Output is correct
20 Correct 185 ms 23932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23924 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 151 ms 23932 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 64 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6216 KB Output is correct
21 Correct 151 ms 23984 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 158 ms 23928 KB Output is correct
24 Correct 151 ms 23936 KB Output is correct
25 Correct 63 ms 14056 KB Output is correct
26 Correct 77 ms 14056 KB Output is correct
27 Correct 154 ms 23940 KB Output is correct
28 Correct 151 ms 23940 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 6 ms 1260 KB Output is correct
37 Correct 151 ms 23980 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 228 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 153 ms 23988 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 64 ms 14068 KB Output is correct
46 Correct 0 ms 300 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 40 ms 6256 KB Output is correct
50 Correct 177 ms 23928 KB Output is correct
51 Correct 160 ms 24008 KB Output is correct
52 Correct 161 ms 23956 KB Output is correct
53 Correct 68 ms 14084 KB Output is correct
54 Correct 63 ms 14076 KB Output is correct
55 Correct 153 ms 23928 KB Output is correct
56 Correct 155 ms 24012 KB Output is correct
57 Correct 64 ms 14116 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 62 ms 14008 KB Output is correct
62 Correct 0 ms 300 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 38 ms 6228 KB Output is correct
66 Correct 62 ms 14080 KB Output is correct
67 Correct 67 ms 14072 KB Output is correct
68 Correct 61 ms 14068 KB Output is correct
69 Correct 62 ms 14072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 152 ms 23924 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 151 ms 23932 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 64 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6216 KB Output is correct
21 Correct 151 ms 23984 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 158 ms 23928 KB Output is correct
24 Correct 151 ms 23936 KB Output is correct
25 Correct 63 ms 14056 KB Output is correct
26 Correct 77 ms 14056 KB Output is correct
27 Correct 154 ms 23940 KB Output is correct
28 Correct 151 ms 23940 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 6 ms 1260 KB Output is correct
37 Correct 151 ms 23980 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 228 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 153 ms 23988 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 64 ms 14068 KB Output is correct
46 Correct 0 ms 300 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 40 ms 6256 KB Output is correct
50 Correct 177 ms 23928 KB Output is correct
51 Correct 160 ms 24008 KB Output is correct
52 Correct 161 ms 23956 KB Output is correct
53 Correct 68 ms 14084 KB Output is correct
54 Correct 63 ms 14076 KB Output is correct
55 Correct 153 ms 23928 KB Output is correct
56 Correct 155 ms 24012 KB Output is correct
57 Correct 64 ms 14116 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 304 KB Output is correct
61 Correct 38 ms 6256 KB Output is correct
62 Correct 150 ms 24012 KB Output is correct
63 Correct 172 ms 24020 KB Output is correct
64 Correct 155 ms 23968 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 39 ms 6216 KB Output is correct
67 Correct 154 ms 23940 KB Output is correct
68 Correct 154 ms 23996 KB Output is correct
69 Correct 155 ms 23940 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 39 ms 6248 KB Output is correct
74 Correct 154 ms 23940 KB Output is correct
75 Correct 188 ms 23928 KB Output is correct
76 Correct 153 ms 24000 KB Output is correct
77 Correct 185 ms 23932 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 62 ms 14008 KB Output is correct
82 Correct 0 ms 300 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 38 ms 6228 KB Output is correct
86 Correct 62 ms 14080 KB Output is correct
87 Correct 67 ms 14072 KB Output is correct
88 Correct 61 ms 14068 KB Output is correct
89 Correct 62 ms 14072 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 824 KB Output is correct
93 Correct 64 ms 14080 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 15 ms 3700 KB Output is correct
98 Correct 59 ms 14028 KB Output is correct
99 Correct 67 ms 14072 KB Output is correct
100 Correct 59 ms 13992 KB Output is correct
101 Correct 60 ms 14080 KB Output is correct
102 Correct 59 ms 14088 KB Output is correct
103 Correct 61 ms 14072 KB Output is correct
104 Correct 59 ms 14064 KB Output is correct
105 Correct 62 ms 14028 KB Output is correct