Submission #29023

# Submission time Handle Problem Language Result Execution time Memory
29023 2017-07-18T06:30:05 Z 김현수(#1170) Park (JOI17_park) C++14
100 / 100
523 ms 2324 KB
#include<bits/stdc++.h>
#include "park.h"
using namespace std;
const int N = 1505;

static int n, pl[N];
static bool dn[N], vis[N], blk[N];

static vector<int> adj[N], tr[N], ord;

void newedg (int A, int B) {
	if(A > B) swap(A, B);
	Answer(A, B);
	adj[A].push_back(B);
	adj[B].push_back(A);
}

void gettree (int I, int P) {
	if(vis[I]) return;
	vis[I] = true;
	if(~P) {
		tr[I].push_back(P);
		tr[P].push_back(I);
	}
	for(auto &T : adj[I]) gettree(T, I);
}

void ins (int I, int P) {
	if(blk[I]) return;
	ord.push_back(I);
	for(auto &T : tr[I]) {
		if(T != P) ins(T, I);
	}
}

void ins (int I) {
	if(vis[I]) return;
	vis[I] = true;
	ord.push_back(I);
	for(auto &T : adj[I]) ins(T);
}

void adde (int R, int I) {
	ord.clear(); ins(R, -1);
	int S = 1, E = ord.size();
	while(S<E) {
		int M = (S+E)/2;
		fill(pl, pl+n, 0);
		for(int i=0;i<M;i++) pl[ord[i]] = true;
		pl[I] = true;
		Ask(min(R, I), max(R, I), pl) ? E = M : S = M+1;
	}
	R = ord[S-1]; blk[R] = true;
	newedg(I, R);
	for(auto &T : tr[R]) {
		if(blk[T]) continue;
		ord.clear(); ins(T, -1);
		fill(pl, pl+n, 0);
		for(auto &P : ord) pl[P] = true;
		pl[I] = true;
		if(Ask(min(T, I), max(T, I), pl)) adde(T, I);
	}
	blk[R] = false;
}

void add (int I) {
	dn[I] = true;
	int R;
	while(true) {
		fill(vis, vis+n, 0);
		ord.clear(); ins(0);
		for(int i=0;i<n;i++) {
			if(!vis[i]) ord.push_back(i);
		}
		int S = 1, E = n;
		while(S<E) {
			int M = (S+E)/2;
			for(int i=0;i<M;i++) pl[ord[i]] = true;
			for(int i=M;i<n;i++) pl[ord[i]] = false;
			pl[I] = true;
			Ask(0, I, pl) ? E = M : S = M+1;
		}
		R = ord[S-1];
		if(!dn[R]) add(R);
		else break;
	}
	for(int i=0;i<n;i++) tr[i].clear();
	fill(vis, vis+n, 0);
	gettree(0, -1);
	blk[R] = true; newedg(R, I);
	for(auto &T : tr[R]) {
		if(blk[T]) continue;
		ord.clear(); ins(T, -1);
		fill(pl, pl+n, 0);
		for(auto &P : ord) pl[P] = true;
		pl[I] = true;
		if(Ask(min(T, I), max(T, I), pl)) adde(T, I);
	}
	blk[R] = false;
}

void Detect(int T, int N) {
	n = N; dn[0] = true;
	for(int i=1;i<n;i++) {
		if(!dn[i]) add(i);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2192 KB Output is correct
2 Correct 9 ms 2192 KB Output is correct
3 Correct 6 ms 2192 KB Output is correct
4 Correct 13 ms 2192 KB Output is correct
5 Correct 29 ms 2192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 513 ms 2324 KB Output is correct
2 Correct 183 ms 2324 KB Output is correct
3 Correct 246 ms 2324 KB Output is correct
4 Correct 523 ms 2324 KB Output is correct
5 Correct 503 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 2324 KB Output is correct
2 Correct 313 ms 2324 KB Output is correct
3 Correct 306 ms 2324 KB Output is correct
4 Correct 253 ms 2324 KB Output is correct
5 Correct 319 ms 2324 KB Output is correct
6 Correct 276 ms 2324 KB Output is correct
7 Correct 289 ms 2324 KB Output is correct
8 Correct 283 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 2324 KB Output is correct
2 Correct 396 ms 2324 KB Output is correct
3 Correct 339 ms 2324 KB Output is correct
4 Correct 419 ms 2324 KB Output is correct
5 Correct 373 ms 2324 KB Output is correct
6 Correct 363 ms 2324 KB Output is correct
7 Correct 406 ms 2324 KB Output is correct
8 Correct 329 ms 2324 KB Output is correct
9 Correct 366 ms 2324 KB Output is correct
10 Correct 396 ms 2324 KB Output is correct
11 Correct 389 ms 2324 KB Output is correct
12 Correct 349 ms 2324 KB Output is correct
13 Correct 409 ms 2324 KB Output is correct
14 Correct 346 ms 2324 KB Output is correct
15 Correct 396 ms 2324 KB Output is correct
16 Correct 313 ms 2324 KB Output is correct
17 Correct 516 ms 2324 KB Output is correct
18 Correct 363 ms 2324 KB Output is correct
19 Correct 446 ms 2324 KB Output is correct
20 Correct 343 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 416 ms 2324 KB Output is correct
2 Correct 366 ms 2324 KB Output is correct
3 Correct 336 ms 2324 KB Output is correct
4 Correct 379 ms 2324 KB Output is correct
5 Correct 406 ms 2324 KB Output is correct
6 Correct 439 ms 2324 KB Output is correct
7 Correct 446 ms 2324 KB Output is correct
8 Correct 406 ms 2324 KB Output is correct
9 Correct 393 ms 2324 KB Output is correct
10 Correct 346 ms 2324 KB Output is correct
11 Correct 356 ms 2324 KB Output is correct
12 Correct 366 ms 2324 KB Output is correct
13 Correct 343 ms 2324 KB Output is correct
14 Correct 396 ms 2324 KB Output is correct
15 Correct 356 ms 2324 KB Output is correct
16 Correct 316 ms 2324 KB Output is correct
17 Correct 513 ms 2324 KB Output is correct
18 Correct 336 ms 2324 KB Output is correct