제출 #1051539

#제출 시각아이디문제언어결과실행 시간메모리
1051539Gromp15식물 비교 (IOI20_plants)C++17
14 / 100
4070 ms9820 KiB
#include <bits/stdc++.h>
#include "plants.h"
#define sz(x) (int)x.size()
using namespace std;

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

void init(int k, std::vector<int> r) {
	n = sz(r);
	adj.resize(n);
	got.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) {
			got[c] = n - i;
			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 got[x] == got[y] ? 0 : got[x] > got[y] ? 1 : -1;
	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...