This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "plants.h"
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
int n, k;
vector<int> got;
vector<int> r;
vector<vector<bool>> can;
void init(int _k, std::vector<int> _r) {
k = _k;
r = _r;
n = sz(r);
if (2 * k > n) {
got.resize(n);
vector<bool> vis(n);
for (int i = 0; i < n; i++) {
vector<int> good;
for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
bool ok = 1;
for (int z = 1; z < k; z++) {
int idx = j - z;
if (idx < 0) idx += n;
if (!vis[idx] && !r[idx]) {
ok = 0; break;
}
}
if (ok) {
good.emplace_back(j);
}
}
if (good.empty()) break;
for (int v : good) vis[v] = 1;
assert(good.size() == 1);
for (int c : good) {
got[c] = n - i;
for (int j = 1; j < k; j++) {
int idx = c - j;
if (idx < 0) idx += n;
r[idx]--;
}
}
}
r = _r;
return;
}
if (n <= 300) {
can.resize(n, vector<bool>(n));
for (int t = 0; t < n; t++) {
r = _r;
vector<bool> vis(n);
for (int i = 0; i < n; i++) {
vector<int> good;
for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
bool ok = 1;
for (int z = 1; z < k; z++) {
int idx = j - z;
if (idx < 0) idx += n;
if (!vis[idx] && !r[idx]) {
ok = 0; break;
}
}
if (ok) {
good.emplace_back(j);
}
}
if (find(all(good), t) != good.end()) good.erase(find(all(good), t));
if (good.empty()) break;
for (int v : good) vis[v] = 1;
for (int c : good) {
for (int j = 1; j < k; j++) {
int idx = c - j;
if (idx < 0) idx += n;
r[idx]--;
}
}
}
for (int i = 0; i < n; i++) can[t][i] = vis[i];
}
}
}
bool win(int x, int y) { // can x be used before y
if (2 * k > n) {
int d = (x - y + n) % n;
if (d < k && !r[y]) return 0;
return got[x] > got[y];
}
return can[y][x];
}
int compare_plants(int x, int y) {
int w1 = win(x, y), w2 = win(y, x);
assert(w1 || w2);
return w1 && w2 ? 0 : w1 ? 1 : -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |