답안 #357946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
357946 2021-01-25T03:42:44 Z ryansee 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
288 ms 24300 KB
#include "supertrees.h"
 
#include "bits/stdc++.h"
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
 
using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 
 
long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (1006)
int p[MAXN];
void init() {
	FOR(i,0,MAXN-1) p[i]=i;
}
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int x,int y) {
	p[find(x)] = find(y);
}
 
vector<vector<int>> v;
void add(int x,int y) {
	v[x][y]=v[y][x]=1;
}
 
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	v.resize(n, vector<int>(n, 0));
	init();
	FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]) merge(i, j);
	FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]==0 && find(i)==find(j)) return 0;
	vector<vector<int>> nodes;
	FOR(i,0,n-1) if(find(i) == i) {
		nodes.pb({});
		FOR(j,0,n-1) if(find(j) == find(i)) {
			nodes.back().eb(j);
		}
	}
	init();
	for(auto i:nodes) {
		for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 1) merge(j, k);
		for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 2 && find(j)==find(k)) return 0;
		for(auto j:i) for(auto k:i) if(p[j][k] == 3) return 0;
		vector<int> tmp;
		for(auto j:i) if(find(j)==j) tmp.eb(j);
		if(siz(tmp) == 2) return 0;
		if(siz(tmp) > 1) FOR(i,0,siz(tmp)-1) add(tmp[i], tmp[(i+1)%siz(tmp)]);
		
		for(auto j:i) if(find(j) ^ j) add(find(j), j);
	}
	build(v);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 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 11 ms 1260 KB Output is correct
7 Correct 270 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 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 11 ms 1260 KB Output is correct
7 Correct 270 ms 24044 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 512 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 1388 KB Output is correct
13 Correct 253 ms 24300 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 876 KB Output is correct
17 Correct 117 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 67 ms 6380 KB Output is correct
21 Correct 271 ms 24172 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 268 ms 24044 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 107 ms 14184 KB Output is correct
26 Correct 107 ms 14188 KB Output is correct
27 Correct 288 ms 24172 KB Output is correct
28 Correct 252 ms 24300 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 1388 KB Output is correct
9 Correct 254 ms 24172 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 256 ms 24096 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 876 KB Output is correct
17 Correct 116 ms 14188 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 64 ms 6380 KB Output is correct
22 Correct 258 ms 24172 KB Output is correct
23 Correct 251 ms 24044 KB Output is correct
24 Correct 265 ms 24172 KB Output is correct
25 Correct 115 ms 14188 KB Output is correct
26 Correct 109 ms 14116 KB Output is correct
27 Correct 255 ms 24044 KB Output is correct
28 Correct 277 ms 24044 KB Output is correct
29 Correct 113 ms 14316 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 64 ms 6380 KB Output is correct
5 Correct 259 ms 24044 KB Output is correct
6 Correct 260 ms 24060 KB Output is correct
7 Correct 271 ms 24040 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 65 ms 6380 KB Output is correct
10 Correct 261 ms 24172 KB Output is correct
11 Correct 254 ms 24044 KB Output is correct
12 Correct 268 ms 24044 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 66 ms 6380 KB Output is correct
17 Correct 255 ms 24044 KB Output is correct
18 Correct 256 ms 24044 KB Output is correct
19 Correct 263 ms 24044 KB Output is correct
20 Correct 254 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 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 11 ms 1260 KB Output is correct
7 Correct 270 ms 24044 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 512 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 1388 KB Output is correct
13 Correct 253 ms 24300 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 876 KB Output is correct
17 Correct 117 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 67 ms 6380 KB Output is correct
21 Correct 271 ms 24172 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 268 ms 24044 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 107 ms 14184 KB Output is correct
26 Correct 107 ms 14188 KB Output is correct
27 Correct 288 ms 24172 KB Output is correct
28 Correct 252 ms 24300 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 1388 KB Output is correct
37 Correct 254 ms 24172 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 256 ms 24096 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 116 ms 14188 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 64 ms 6380 KB Output is correct
50 Correct 258 ms 24172 KB Output is correct
51 Correct 251 ms 24044 KB Output is correct
52 Correct 265 ms 24172 KB Output is correct
53 Correct 115 ms 14188 KB Output is correct
54 Correct 109 ms 14116 KB Output is correct
55 Correct 255 ms 24044 KB Output is correct
56 Correct 277 ms 24044 KB Output is correct
57 Correct 113 ms 14316 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 876 KB Output is correct
61 Correct 113 ms 14188 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 68 ms 6380 KB Output is correct
66 Correct 111 ms 14188 KB Output is correct
67 Correct 118 ms 14188 KB Output is correct
68 Correct 105 ms 14188 KB Output is correct
69 Correct 108 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 380 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 11 ms 1260 KB Output is correct
7 Correct 270 ms 24044 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 512 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 1388 KB Output is correct
13 Correct 253 ms 24300 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 876 KB Output is correct
17 Correct 117 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 67 ms 6380 KB Output is correct
21 Correct 271 ms 24172 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 268 ms 24044 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 107 ms 14184 KB Output is correct
26 Correct 107 ms 14188 KB Output is correct
27 Correct 288 ms 24172 KB Output is correct
28 Correct 252 ms 24300 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 1388 KB Output is correct
37 Correct 254 ms 24172 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 256 ms 24096 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 116 ms 14188 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 64 ms 6380 KB Output is correct
50 Correct 258 ms 24172 KB Output is correct
51 Correct 251 ms 24044 KB Output is correct
52 Correct 265 ms 24172 KB Output is correct
53 Correct 115 ms 14188 KB Output is correct
54 Correct 109 ms 14116 KB Output is correct
55 Correct 255 ms 24044 KB Output is correct
56 Correct 277 ms 24044 KB Output is correct
57 Correct 113 ms 14316 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 64 ms 6380 KB Output is correct
62 Correct 259 ms 24044 KB Output is correct
63 Correct 260 ms 24060 KB Output is correct
64 Correct 271 ms 24040 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 65 ms 6380 KB Output is correct
67 Correct 261 ms 24172 KB Output is correct
68 Correct 254 ms 24044 KB Output is correct
69 Correct 268 ms 24044 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 66 ms 6380 KB Output is correct
74 Correct 255 ms 24044 KB Output is correct
75 Correct 256 ms 24044 KB Output is correct
76 Correct 263 ms 24044 KB Output is correct
77 Correct 254 ms 24172 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 876 KB Output is correct
81 Correct 113 ms 14188 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 68 ms 6380 KB Output is correct
86 Correct 111 ms 14188 KB Output is correct
87 Correct 118 ms 14188 KB Output is correct
88 Correct 105 ms 14188 KB Output is correct
89 Correct 108 ms 14188 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 876 KB Output is correct
93 Correct 112 ms 14188 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 27 ms 3820 KB Output is correct
98 Correct 112 ms 14188 KB Output is correct
99 Correct 107 ms 14188 KB Output is correct
100 Correct 106 ms 14188 KB Output is correct
101 Correct 118 ms 14188 KB Output is correct
102 Correct 111 ms 14200 KB Output is correct
103 Correct 125 ms 14188 KB Output is correct
104 Correct 125 ms 14184 KB Output is correct
105 Correct 117 ms 14188 KB Output is correct