Submission #1051535

#TimeUsernameProblemLanguageResultExecution timeMemory
1051535Gromp15Comparing Plants (IOI20_plants)C++17
0 / 100
4094 ms64336 KiB
#include <bits/stdc++.h>
#include "plants.h"
#define sz(x) (int)x.size()
using namespace std;

int n;
vector<vector<int>> adj;

void init(int k, std::vector<int> r) {
	n = sz(r);
	adj.resize(n);
	vector<bool> vis(n);
	for (int i = 0; i < n; i++) {
		vector<int> good;
		for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
			bool ok = 1;
			for (int z = 1; z < k; z++) {
				int idx = j - z;
				if (idx < 0) idx += n;
				if (!vis[idx] && !r[idx]) {
					ok = 0; break;
				}
			}
			if (ok) {
				good.emplace_back(j);
			}
		}
		if (good.empty()) break;
		for (int v : good) vis[v] = 1;
		for (int c : good) for (int j = 0; j < n; j++) if (!vis[j]) adj[c].emplace_back(j);
		for (int c : good) {
			for (int j = 1; j < k; j++) {
				int idx = c - j;
				if (idx < 0) idx += n;
				r[idx]--;
			}
		}
	}
}

bool reachable(int x, int y) {
	vector<bool> vis(n);
	auto dfs = [&](auto&& s, int v) -> void {
		vis[v] = 1;
		for (int u : adj[v]) if (!vis[u]) s(s, u);
	};
	dfs(dfs, x);
	return vis[y];
}

int compare_plants(int x, int y) {
	assert(!reachable(x, y) || !reachable(y, x));
	return reachable(x, y) ? 1 : reachable(y, x) ? -1 : 0;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...