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 "plants.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
const int N = 5010;
const int oo = 2e9;
queue<int> q;
vector<int> vc, g[N];
int per[N], mrk[N], tt = 0;
bool sml[N][N];
void init(int k, vector<int> r) {
int n = sz(r);
for (int it = n - 1; it >= 0; it--){
vc.clear();
for (int i = 0; i < n; i++)
if (r[i] == 0)
vc.PB(i);
int cand = -1;
for (int it = 0; it < sz(vc); it++){
int cur = vc[it];
int pre = vc[(it + sz(vc) - 1) % sz(vc)];
if (pre < cur){
if (pre - cur + n >= k){
cand = cur;
break;
}
} else {
if (pre - cur >= k){
cand = cur;
break;
}
}
}
per[cand] = it;
r[cand] = oo;
for (int i = 1, loc = cand; i < k; i++){
loc = (loc + n - 1) % n;
r[loc]--;
if (r[loc] < oo / 2)
g[cand].PB(loc);
}
for (int i = 1, loc = cand; i < k; i++){
loc = (loc + 1) % n;
if (r[loc] < oo / 2)
g[cand].PB(loc);
}
}
for (int i = 0; i < n; i++){
tt++;
q.push(i);
mrk[i] = tt;
while (sz(q)){
int v = q.front(); q.pop();
sml[i][v] = 1;
for (int u : g[v])
if (mrk[u] < tt){
mrk[u] = tt;
q.push(u);
}
}
}
return;
}
int compare_plants(int x, int y) {
if (sml[x][y]) return 1;
if (sml[y][x]) return -1;
return 0;
}
# | 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... |