# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
686665 | ethening | Gondola (IOI14_gondola) | 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 "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define DEBUG 0
int subtask;
int n;
vector<int> a;
bool check(vector<int> &a) {
unordered_map<int, int> pos;
for (int i = 0; i < n; i++) {
if (pos.count(a[i])) {
return false;
}
else {
pos[a[i]] = i;
}
}
int mnVal = -1;
int mnPos = -1;
for (int i = 1; i <= n; i++) {
if (pos.count(i)) continue;
if (mnVal == -1) {
mnVal = i;
mnPos = pos[i];
}
else {
int curVal = i;
int curPos = pos[i];
int expectPos = (mnPos + (curVal - mnVal)) % n;
if (expectPos != curPos) return false;
}
}
return true;
}
vector<int> rotate(vector<int> &a) {
vector<int> ret(n);
int mnDex = 0;
int mnVal = a[0];
for (int i = 0; i < n; i++) {
if (a[i] < mnVal) {
mnVal = a[i];
mnDex = i;
}
}
if (mnVal > n) return a;
for (int i = mnDex, j = mnVal - 1; i < mnDex + n; i++, j++) {
ret[j % n] = a[i % n];
}
return ret;
}
void construct(vector<int> &a) {
const int MAXV = 250000;
int mxDex = 0;
int mxVal = a[0];
vector<int> pos(MAXV + 5, -1);
for (int i = 0; i < n; i++) {
if (a[i] > mxVal) {
mxVal = a[i];
mxDex = i;
}
pos[a[i]] = i;
}
cout << mxVal - n << "\n";
int tmp = mxDex + 1;
for (int i = n + 1; i <= mxVal; i++) {
if (pos[i] == -1 || i == mxVal) {
cout << tmp << "\n";
tmp = i;
}
else {
cout << pos[i] + 1 << "\n";
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> subtask;
cin >> n;
a = vector<int>(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (subtask <= 3) {
bool valid = check(a);
cout << (valid ? 1 : 0) << "\n";
}
else if (subtask <= 6) {
a = rotate(a);
if (DEBUG) {
for (int i = 0; i < n; i++) {
cout << a[i] << " \n"[i == n - 1];
}
}
construct(a);
}
else {
bool valid = check(a);
if (!valid) {
cout << 0 << "\n";
return 0;
}
}
}