Submission #556418

#TimeUsernameProblemLanguageResultExecution timeMemory
556418MilosMilutinovicComparing Plants (IOI20_plants)C++14
0 / 100
4067 ms11224 KiB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

const int MX = 5005;

int L[MX], R[MX];
bool was[MX];

void init(int k, vector<int> r) {
    int n = r.size(), cs = n;
    for (int i = 0; i < n; i++) {
        vector<int> ids;
        for (int j = 0; j < n; j++) {
            if (was[j] || r[j] != 0) continue;
            int prv = j;
            bool ok = true;
            for (int p = 0; p < k - 1; p++) {
                prv = (prv - 1 + n) % n;
                if (r[prv] == 0 && !was[prv]) ok = false;
            }
            if (ok) ids.push_back(j);
        }
        for (int j : ids)  {
            L[j] = cs - ids.size() + 1;
            R[j] = cs;
            was[j] = true;
            int prv = j;
            for (int p = 0; p < k - 1; p++) {
                prv = (prv - 1 + n) % n;
                r[prv] -= 1;
            }
        }
        cs -= ids.size();
    }
}

int compare_plants(int x, int y) {
    return (L[x] > R[y] ? 1 : (R[x] < L[y] ? -1 : 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...