# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577829 | Markomafko972 | Art Collections (BOI22_art) | C++17 | 0 ms | 0 KiB |
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 "art.h"
#include <bits/stdc++.h>
#include <vector>
void solve(int n) {
vector<int> v[4005];
int a[4005];
for (int i = 0; i < n; i++) {
v[i].clear();
for (int j = 0; j < n; j++) {
v[i].push_back((i+j)%n+1);
}
a[i] = publish(v[i]);
}
vector<int> sol;
for (int i = n-1; i >= 1; i--) {
int p = 0, da = 0;
for (int j = 0; j < n; j++) {
while (p < n && (p <= j || a[p] == -1)) p++;
if (p >= n) break;
if (a[p]-a[j] == i) {
a[j] = -1;
sol.push_back(j+1);
da = 1;
int d = 1;
while (j-d >= 0) {
if (a[j-d] != -1) a[j-d] -= d;
d++;
}
d = 1;
while (j+d < n) {
if (a[j+d] != -1) a[j+d] -= i-d+1;
d++;
}
break;
}
}
if (da == 0) {
if (a[0]-a[n-1] == i) {
a[n-1] = -1;
sol.push_back(n);
for (int j = n-2; j >= 0; j--) {
if (a[j] != -1) a[j] -= (n-1)-j;
}
}
else assert(0);
}
}
for (int i = 0; i < n; i++) {
if (a[i] != -1) sol.push_back(i);
}
answer(sol);
}