Submission #838116

#TimeUsernameProblemLanguageResultExecution timeMemory
838116caganyanmazComparing Plants (IOI20_plants)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; #ifdef DEBUGGING #include "../debug.h" #else #define debug(x...) void(42) #endif constexpr static int MXN = 2e5 + 5; int k, n; int fw[MXN]; void update(int i, int val) { for (i++;i<MXN;i+=i&(-i)) fw[i] += val; } int get(int i) { int res = 0; for (i++;i;i-=i&(-i)) res += fw[i]; return res; } int get(int l, int r) { return get(r) - get(l); } int v[MXN]; int succ[MXN]; void init(int _k, vector<int> r) { debug(r); n = r.size(); k = _k; assert(k * 2 > n); fill(succ, succ + n, -1); for (int i = 1; i <= n; i++) { int prev = -1; int current = -1; int first = MXN; for (int j = 0; j < n; j++) { if (v[j]) continue; int ll = j+1; int rr = j+k; int pc = 0; if (rr > n) { pc += get(ll, n); pc += get(0, rr-n); } else { pc += get(ll, rr); } if (pc + r[j] < k-1) continue; first = min(first, j); if (prev != -1 && j - prev >= k) current = j; } if (current == -1) current = first; debug(current); v[current] = i; update(current, 1); } } int compare_plants(int x, int y) { if (v[x] > v[y]) return 1; if (v[y] > v[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...