Submission #1282681

#TimeUsernameProblemLanguageResultExecution timeMemory
1282681nikaa123Park (JOI17_park)C++20
0 / 100
2 ms572 KiB
#include "park.h"
#include <bits/stdc++.h>
using namespace std;
// #define int int

int p[1405];
int f[1405];
int n;

vector <int> lst, nodes,vis(1405),seen(1405);
vector <vector<int>> v(1405);

void colect(int x) {
	seen[x] = 1;
	nodes.push_back(x);
	for (auto to:v[x]) {
		if (!vis[to] && !seen[to]) colect(to);
	}
}

void dfs(int x, int node) {
	while (true) {
		if (vis[x]) return;
		for (int i = 0; i < n; i++) {
			seen[i] = 0;
		}
		nodes.clear();
		colect(x);
		for (int i = 0; i < n; i++) {
			p[i] = 0;
		}
		for (auto to:nodes) {
			p[to] = 1;
		}
		p[node] = 1;
		if (!Ask(min(node,x),max(node,x),p)) {
			return;
		}
		int l = 0; int r =(nodes.size())-1;
		int res = -1;
		while (l <= r) {
			int mid = (l+r)/2;
			for (int i = 0; i < n; i++) {
				p[i] = 0;
			}
			for (int i = 0; i <= mid; i++) {
				p[nodes[i]] = 1;
			}
			p[node] = p[x] = 1;
			if (Ask(min(node,x),max(node,x),p)) {
				res = nodes[mid];
				r = mid - 1;
			} else {
				l = mid +1;
			}
		}
		vis[res] = 1;
		lst.push_back(res);
		for (auto to:v[res]) {
			dfs(to,node);
		}
	}
}

void explore(int x) {
	if (f[x]) {
		return;
	}

	for (int i = 0; i < n; i++) {
		p[i] = f[i];
	}
	p[x] = 1;
	while (!Ask(0,x,p)) {
		int l = 0; int r = n-1;
		int res;
		while (l <= r) {
			int mid = (l+r)/2;
			for (int i = 0; i < n; i++) {
				if (f[i] || i<= mid) {
					p[i] = 1;
				} else {
					p[i] = 0;
				}
			}
			p[x] = 1;
			p[0] = 1;
			if (Ask(0,x,p)) {
				res = mid;
				r = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		explore(res);
	}
	for (int i = 1; i <= n; i++) {
		vis[i] = 0;
	}
	lst.clear();
	dfs(0,x);

	for (auto u:lst) {
		Answer(min(u,x),max(u,x));
	}
	v[nodes[0]].push_back(x);
	f[x] = 1;
}


void Detect(int T, int N) {
	n = N;
	for (int i = 0; i < n; i++) {
		f[i] = 0;
		p[i] = 0;
	}
	f[0] = 1;
	for (int i = 0; i < n; i++) {
		if (f[i]) continue;
		explore(i);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...