Submission #838143

#TimeUsernameProblemLanguageResultExecution timeMemory
838143caganyanmazComparing Plants (IOI20_plants)C++17
14 / 100
4043 ms5216 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; //#define DEBUGGING #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>0;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] != 0) continue; int ll = j+1; int rr = j+k; int pc = 0; if (j == 1) debug(ll, rr); if (rr > n) pc = get(ll, n) + get(0, rr-n); else pc = get(ll, rr); debug(i, j, pc, pc + r[j], prev); if (pc + r[j] < k-1) continue; first = min(first, j); if (prev != -1 && j - prev >= k) current = j; prev = 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...