Submission #1079491

#TimeUsernameProblemLanguageResultExecution timeMemory
1079491bleahbleahComparing Plants (IOI20_plants)C++17
0 / 100
4098 ms604 KiB
#include "plants.h" #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; #define sz(x) ((int)(x).size()) int K, N; const int nmax = 2e5 + 5; namespace Queue { int next[nmax]; int inside[nmax]; set<int> heads; void insert(int node) { heads.emplace(node); inside[node] = 1; next[node] = -1; for(int i = (node + 1) % N, d = 1; d < K; d++, i = (i + 1) % N) { if(inside[i]) { if(heads.count(i)) heads.erase(i); next[node] = i; } } for(int i = (node - 1 + N) % N, d = 1; d < K; d++, i = (i - 1 + N) % N) { if(inside[i]) { heads.erase(node); next[i] = node; } } } vector<int> prune() { vector<int> rez; for(auto x : heads) rez.emplace_back(x), inside[x] = 0; heads.clear(); for(auto x : rez) if(next[x] != -1) heads.emplace(x); return rez; } } vector<int> topsort; void init(int k__, std::vector<int> r) { K = k__; N = sz(r); topsort.resize(N); for(int i = 0; i < sz(r); i++) { if(r[i] == 0) Queue::insert(i); } int color = 0; while(sz(Queue::heads)) { auto rem = Queue::prune(); ++color; for(auto x : rem) topsort[x] = color; for(auto x : rem) { for(int i = (x - 1 + N) % N, d = 1; d < K; d++, i = (i - 1 + N) % N) { r[i]--; if(r[i] == 0) Queue::insert(i); } } } return; } int compare_plants(int x, int y) { return topsort[x] < topsort[y]? 1 : topsort[x] == topsort[y]? 0 : -1; }
#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...