Submission #1062601

#TimeUsernameProblemLanguageResultExecution timeMemory
1062601vjudge1Comparing Plants (IOI20_plants)C++17
11 / 100
4115 ms2097152 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; using vi = vector<int>; vector<vi> L; vi dfs(int u0) { int n = int(L.size()); vi viz(n, 0); function<void(int)> dfs0 = [&](int u) { if(viz[u]) return; viz[u] = 1; for(auto it : L[u]) { if(it != u) dfs0(it); } }; dfs0(u0); return viz; } vector<vi> Reach; void init(int k, vi r) { int n = int(r.size()); vi active(n, 1); L.resize(n); set<int> Zero; for(int i = 0; i < n; ++i) if(!r[i]) Zero.insert(i); for(int i = 0; i < n; ++i) { int v = 0; for(auto it : Zero) { int ok = 1; for(int j = 1; j < k; ++j) { int p = (it - j + n) % n; if(active[p] && !r[p]) { ok = 0; break; } } if(ok) { v = it; break; } } Zero.erase(v); active[v] = 0; for(int j = 1; j < k; ++j) { int p = (v - j + n) % n; if(active[p]) { --r[p]; L[v].push_back(p); if(!r[p]) { Zero.insert(p); } } ///^ oare si fara !r[p] e ok rationamentul int p2 = (v + j) % n; if(active[p2]) { L[v].push_back(p2); /// nu puteau fi popite } } } for(int i = 0; i < n; ++i) Reach.push_back(dfs(i)); } int compare_plants(int x, int y) { if(Reach[x][y]) return 1; if(Reach[y][x]) return -1; return 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...