Submission #1051472

#TimeUsernameProblemLanguageResultExecution timeMemory
1051472Gromp15Comparing Plants (IOI20_plants)C++17
0 / 100
1 ms352 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> 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 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...