답안 #124293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124293 2019-07-03T00:41:28 Z wilwxk Amusement Park (JOI17_amusement_park) C++14
100 / 100
410 ms 135188 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MAXN=1e5+5;
static unordered_set<int> g[MAXN];
static unordered_set<int> comp[MAXN], leaves[MAXN];
static int cor[MAXN], prof[MAXN];
static queue<int> qu;
static int n, m;
static ll x;
 
static void inicia(int cur) {
	cor[cur]=-1;
	for(auto viz : g[cur]) {
		if(cor[viz]) continue;
		prof[viz]=prof[cur]+1;
		inicia(viz);
	}
}
 
static void predfs(int cur) {
	comp[0].insert(cur);
	cor[cur]=comp[0].size()-1;
	int ok=0;
	for(auto viz : g[cur]) {
		if(abs(prof[cur]-prof[viz])!=1||cor[viz]!=-1) continue;
		if(comp[0].size()<60) predfs(viz), ok++;
		else if(cor[viz]==-1) qu.push(viz);
	}
	if(!ok||(cur==0&&ok==1)) leaves[0].insert(cur);
}
 
void Joi(int N, int M, int A[], int B[], long long X, int T) {
	n=N; m=M; x=X; for(int i=0; i<m; i++) g[A[i]].insert(B[i]), g[B[i]].insert(A[i]);
	inicia(0); predfs(0);
	for(int i=1; i<n; i++) if(cor[i]!=-1) comp[i]=comp[0], leaves[i]=leaves[0];
	while(qu.size()) {
		int cur=qu.front(); qu.pop();
		if(comp[cur].size()) continue;
		for(auto viz : g[cur]) {
			if(cor[viz]==-1) qu.push(viz);
			else if(comp[cur].empty()) {
				comp[cur]=comp[viz]; comp[cur].insert(cur);
				leaves[cur]=leaves[viz]; leaves[cur].insert(cur);
				int leaf; for(auto cara : leaves[viz]) if(cara!=viz) leaf=cara;
				int nleaf, aux=0;
				for(auto cara : comp[viz]) if(abs(prof[cara]-prof[leaf])==1&&g[leaf].find(cara)!=g[leaf].end()) nleaf=cara;
				for(auto cara : comp[viz]) if(abs(prof[cara]-prof[nleaf])==1&&g[nleaf].find(cara)!=g[nleaf].end()) aux++;
				if(aux==2) leaves[cur].insert(nleaf);
				comp[cur].erase(leaf);
				leaves[cur].erase(leaf);
				leaves[cur].erase(viz);
				cor[cur]=cor[leaf];
			}
		}
	}
 
	// for(auto cur : leaves[61]) printf("%d ", cur);
	for(int i=0; i<n; i++) {
		ll mask=0;
		for(auto cara : comp[i]) mask|=(1LL<<cor[cara]);
		if(mask!=(1LL<<60)-1) printf("erro!! %d >> %lld\n", i, mask);
	}
 
	for(int i = 0; i < N; i++) MessageBoard(i, (bool)(x&(1LL<<cor[i])));
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MAXN=1e5+5;
unordered_set<int> g[MAXN];
unordered_set<int> comp[MAXN], leaves[MAXN];
int cor[MAXN], prof[MAXN];
queue<int> qu;
int n, m;
ll x, respf, mask;
 
void inicia(int cur) {
	cor[cur]=-1;
	for(auto viz : g[cur]) {
		if(cor[viz]) continue;
		prof[viz]=prof[cur]+1;
		inicia(viz);
	}
}
 
void predfs(int cur) {
	comp[0].insert(cur);
	cor[cur]=comp[0].size()-1;
	int ok=0;
	for(auto viz : g[cur]) {
		if(abs(prof[cur]-prof[viz])!=1||cor[viz]!=-1) continue;
		if(comp[0].size()<60) predfs(viz), ok++;
		else if(cor[viz]==-1) qu.push(viz);
	}
	if(!ok||(cur==0&&ok==1)) leaves[0].insert(cur);
}
 
 
void resolve(int cur, int p) {
	// printf("resolve %d\n", cur);
	comp[p].erase(cur);
	for(auto viz : g[cur]) {
		if(comp[p].find(viz)==comp[p].end()) continue;
		if(Move(viz)) respf|=(1LL<<cor[viz]);
		mask|=(1LL<<cor[viz]);
		resolve(viz, p);
		Move(cur);
	}
}
 
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	n=N; m=M; for(int i=0; i<m; i++) g[A[i]].insert(B[i]), g[B[i]].insert(A[i]);
	inicia(0); predfs(0);
	for(int i=1; i<n; i++) if(cor[i]!=-1) comp[i]=comp[0], leaves[i]=leaves[0];
	while(qu.size()) {
		int cur=qu.front(); qu.pop();
		if(comp[cur].size()) continue;
		for(auto viz : g[cur]) {
			if(cor[viz]==-1) qu.push(viz);
			else if(comp[cur].empty()) {
				comp[cur]=comp[viz]; comp[cur].insert(cur);
				leaves[cur]=leaves[viz]; leaves[cur].insert(cur);
				int leaf; for(auto cara : leaves[viz]) if(cara!=viz) leaf=cara;
				int nleaf, aux=0;
				for(auto cara : comp[viz]) if(abs(prof[cara]-prof[leaf])==1&&g[leaf].find(cara)!=g[leaf].end()) nleaf=cara;
				for(auto cara : comp[viz]) if(abs(prof[cara]-prof[nleaf])==1&&g[nleaf].find(cara)!=g[nleaf].end()) aux++;
				if(aux==2) leaves[cur].insert(nleaf);
				comp[cur].erase(leaf);
				leaves[cur].erase(leaf);
				leaves[cur].erase(viz);
				cor[cur]=cor[leaf];
			}
		}
	}
 
	// for(auto cur : comp[P]) printf("%d ", cur); cout << endl;
 
	if(V) respf|=(1LL<<cor[P]);
	mask|=(1LL<<cor[P]);
	resolve(P, P);
 
	// printf("mask= %lld // respf= %lld // %d <> %lld\n", mask, respf, comp[P].size(), *comp[P].begin());
	return respf;
}

Compilation message

Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:47:9: warning: 'leaf' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int leaf; for(auto cara : leaves[viz]) if(cara!=viz) leaf=cara;
         ^~~~

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:60:9: warning: 'leaf' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int leaf; for(auto cara : leaves[viz]) if(cara!=viz) leaf=cara;
         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 34424 KB Output is correct
2 Correct 39 ms 34804 KB Output is correct
3 Correct 43 ms 35836 KB Output is correct
4 Correct 38 ms 34292 KB Output is correct
5 Correct 38 ms 34420 KB Output is correct
6 Correct 39 ms 34944 KB Output is correct
7 Correct 40 ms 35456 KB Output is correct
8 Correct 44 ms 36476 KB Output is correct
9 Correct 41 ms 35708 KB Output is correct
10 Correct 38 ms 34676 KB Output is correct
11 Correct 45 ms 35392 KB Output is correct
12 Correct 36 ms 34036 KB Output is correct
13 Correct 42 ms 35836 KB Output is correct
14 Correct 55 ms 36004 KB Output is correct
15 Correct 42 ms 35708 KB Output is correct
16 Correct 42 ms 35432 KB Output is correct
17 Correct 42 ms 35964 KB Output is correct
18 Correct 42 ms 35460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 92212 KB Output is correct
2 Correct 255 ms 92320 KB Output is correct
3 Correct 255 ms 92076 KB Output is correct
4 Correct 280 ms 108300 KB Output is correct
5 Correct 225 ms 89612 KB Output is correct
6 Correct 242 ms 94396 KB Output is correct
7 Correct 224 ms 89656 KB Output is correct
8 Correct 235 ms 95244 KB Output is correct
9 Correct 241 ms 96524 KB Output is correct
10 Correct 410 ms 135188 KB Output is correct
11 Correct 404 ms 133776 KB Output is correct
12 Correct 253 ms 99060 KB Output is correct
13 Correct 248 ms 99060 KB Output is correct
14 Correct 261 ms 101616 KB Output is correct
15 Correct 248 ms 95236 KB Output is correct
16 Correct 241 ms 93880 KB Output is correct
17 Correct 281 ms 106904 KB Output is correct
18 Correct 291 ms 109320 KB Output is correct
19 Correct 280 ms 106760 KB Output is correct
20 Correct 201 ms 89912 KB Output is correct
21 Correct 196 ms 89076 KB Output is correct
22 Correct 234 ms 94704 KB Output is correct
23 Correct 231 ms 94604 KB Output is correct
24 Correct 232 ms 94656 KB Output is correct
25 Correct 230 ms 94732 KB Output is correct
26 Correct 228 ms 94604 KB Output is correct
27 Correct 229 ms 94860 KB Output is correct
28 Correct 258 ms 94608 KB Output is correct
29 Correct 214 ms 89204 KB Output is correct
30 Correct 249 ms 91520 KB Output is correct
31 Correct 39 ms 34804 KB Output is correct
32 Correct 38 ms 34820 KB Output is correct
33 Correct 42 ms 36476 KB Output is correct
34 Correct 43 ms 35064 KB Output is correct
35 Correct 36 ms 34164 KB Output is correct
36 Correct 37 ms 34164 KB Output is correct
37 Correct 36 ms 34036 KB Output is correct
38 Correct 36 ms 34192 KB Output is correct
39 Correct 36 ms 34036 KB Output is correct
40 Correct 37 ms 34268 KB Output is correct
41 Correct 37 ms 34428 KB Output is correct
42 Correct 37 ms 34252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 34164 KB Output is correct
2 Correct 36 ms 34148 KB Output is correct
3 Correct 36 ms 34164 KB Output is correct
4 Correct 60 ms 42656 KB Output is correct
5 Correct 61 ms 42720 KB Output is correct
6 Correct 60 ms 42656 KB Output is correct
7 Correct 61 ms 42528 KB Output is correct
8 Correct 62 ms 42632 KB Output is correct
9 Correct 204 ms 89304 KB Output is correct
10 Correct 199 ms 89348 KB Output is correct
11 Correct 199 ms 89272 KB Output is correct
12 Correct 43 ms 34044 KB Output is correct
13 Correct 37 ms 34164 KB Output is correct
14 Correct 41 ms 34152 KB Output is correct
15 Correct 44 ms 34044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 92400 KB Output is correct
2 Correct 256 ms 92212 KB Output is correct
3 Correct 248 ms 92408 KB Output is correct
4 Correct 277 ms 105796 KB Output is correct
5 Correct 226 ms 89748 KB Output is correct
6 Correct 240 ms 95892 KB Output is correct
7 Correct 235 ms 94828 KB Output is correct
8 Correct 223 ms 91052 KB Output is correct
9 Correct 232 ms 94692 KB Output is correct
10 Correct 385 ms 131672 KB Output is correct
11 Correct 394 ms 133928 KB Output is correct
12 Correct 249 ms 99056 KB Output is correct
13 Correct 249 ms 98260 KB Output is correct
14 Correct 258 ms 101944 KB Output is correct
15 Correct 242 ms 93360 KB Output is correct
16 Correct 256 ms 93956 KB Output is correct
17 Correct 283 ms 107456 KB Output is correct
18 Correct 265 ms 104716 KB Output is correct
19 Correct 280 ms 107916 KB Output is correct
20 Correct 207 ms 90128 KB Output is correct
21 Correct 213 ms 88984 KB Output is correct
22 Correct 248 ms 94612 KB Output is correct
23 Correct 234 ms 94876 KB Output is correct
24 Correct 236 ms 94624 KB Output is correct
25 Correct 230 ms 94960 KB Output is correct
26 Correct 230 ms 94612 KB Output is correct
27 Correct 232 ms 94840 KB Output is correct
28 Correct 235 ms 94720 KB Output is correct
29 Correct 213 ms 89176 KB Output is correct
30 Correct 222 ms 91528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 261 ms 92204 KB Output is correct
2 Correct 261 ms 92340 KB Output is correct
3 Correct 273 ms 92436 KB Output is correct
4 Correct 332 ms 106720 KB Output is correct
5 Correct 225 ms 91484 KB Output is correct
6 Correct 226 ms 91492 KB Output is correct
7 Correct 227 ms 91360 KB Output is correct
8 Correct 247 ms 103480 KB Output is correct
9 Correct 232 ms 94588 KB Output is correct
10 Correct 396 ms 133436 KB Output is correct
11 Correct 410 ms 131460 KB Output is correct
12 Correct 248 ms 98524 KB Output is correct
13 Correct 254 ms 99136 KB Output is correct
14 Correct 264 ms 101900 KB Output is correct
15 Correct 280 ms 105848 KB Output is correct
16 Correct 248 ms 93308 KB Output is correct
17 Correct 286 ms 108564 KB Output is correct
18 Correct 289 ms 108604 KB Output is correct
19 Correct 309 ms 107676 KB Output is correct
20 Correct 200 ms 90020 KB Output is correct
21 Correct 199 ms 89352 KB Output is correct
22 Correct 260 ms 94856 KB Output is correct
23 Correct 238 ms 94612 KB Output is correct
24 Correct 232 ms 94568 KB Output is correct
25 Correct 247 ms 94736 KB Output is correct
26 Correct 236 ms 94648 KB Output is correct
27 Correct 254 ms 94944 KB Output is correct
28 Correct 237 ms 94952 KB Output is correct
29 Correct 210 ms 89204 KB Output is correct
30 Correct 225 ms 91648 KB Output is correct
31 Correct 39 ms 34924 KB Output is correct
32 Correct 39 ms 34932 KB Output is correct
33 Correct 42 ms 36348 KB Output is correct
34 Correct 39 ms 34848 KB Output is correct
35 Correct 36 ms 34180 KB Output is correct
36 Correct 39 ms 34220 KB Output is correct
37 Correct 41 ms 34168 KB Output is correct
38 Correct 41 ms 34288 KB Output is correct
39 Correct 36 ms 34036 KB Output is correct
40 Correct 40 ms 34516 KB Output is correct
41 Correct 40 ms 34316 KB Output is correct
42 Correct 41 ms 34484 KB Output is correct