Submission #1051472

# Submission time Handle Problem Language Result Execution time Memory
1051472 2024-08-10T07:17:29 Z Gromp15 Comparing Plants (IOI20_plants) C++17
0 / 100
1 ms 352 KB
#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> idx;
		for (int j = 0; j < n; j++) if (!vis[j]) {
			if (!r[j]) idx.emplace_back(j), vis[j] = 1;
		}
		if (idx.empty()) return;
		for (int v : idx) {
			for (int j = 1; j < k; j++) {
				int u = (v + j) % n;
				if (!vis[u]) { 
					adj[v].emplace_back(u);
				}
			}
			for (int j = 1; j < k; j++) {
				int u = (v - j + n) % n;
				if (vis[u]) break;
				adj[v].emplace_back(u);
			}
		}
		for (int v : idx) {
			vis[v] = 1;
			for (int j = 1; j < k; j++) {
				int u = (v - j + n) % n;
				r[u]--;
			}
		}
	}
	for (int i = 0; i < n; i++) assert(vis[i]);
}

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 time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 352 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -