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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
struct PS {
vector<int> psum;
PS(int n): psum(n + 1) {}
void add(int l, int r, int x) {
psum[l] += x;
psum[r + 1] -= x;
}
vector<int> compute() const {
vector<int> ans(sz(psum));
partial_sum(begin(psum), end(psum), ans.begin());
return ans;
}
};
const int maxn = 1005;
int ans[maxn][maxn];
void init(int k, vector<int> arr) {
int n = sz(arr);
bool vis[n] {};
auto irange = [&](int x, int y) -> bool {
if (x + k >= n && y < x + k - n) {
return true;
}
return x <= y && y < x + k;
};
for (int i = 0; i < n; i++) {
PS ps(n * 2);
for (int j = 0; j < n; j++) {
if (!vis[j] && !arr[j]) {
ps.add(j + 1, j + k - 1, 1);
}
}
auto psv = ps.compute();
for (int j = 0; j < n; j++) {
if (!psv[j] && !psv[j + n] && !arr[j]) {
vis[j] = true;
for (int a = 0; a < n; a++) {
if (irange(a, j)) {
arr[a]--;
}
if (!vis[a] && (irange(a, j) || irange(j, a))) {
ans[j][a] = 1;
ans[a][j] = -1;
}
}
break;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (ans[j][i] && ans[j][i] == ans[i][k]) {
ans[j][k] = ans[j][i];
}
}
}
}
}
int compare_plants(int x, int y) {
return ans[x][y];
}
# | 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... |