Submission #1079505

#TimeUsernameProblemLanguageResultExecution timeMemory
1079505bleahbleahComparing Plants (IOI20_plants)C++17
0 / 100
2 ms348 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) { cerr << "inserez " << node << '\n'; heads.emplace(node); inside[node] = 1; next[node] = -1; for(int i = (node + 1) % N, d = 1; i != node && 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; i != node && 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(next[x]); return rez; } } vector<int> topsort; void init(int k__, std::vector<int> r) { K = k__; N = sz(r); topsort.resize(N); vector<int> erased(N, 0); for(int i = 0; i < sz(r); i++) if(r[i] == 0) erased[i] = 1, Queue::insert(i); int color = 0; while(sz(Queue::heads)) { auto rem = Queue::prune(); //for(auto x : rem) cerr << x << ' '; //cerr << '\n'; ++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) { if(erased[i]) continue; r[i]--; if(r[i] == 0) erased[i] = 1, 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...