# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269043 | kawhiet | Gondola (IOI14_gondola) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int gondolaSequence[100001];
int replacementSequence[250001];
int valid(int n, int inputSeq[]) {
vector<int> a(n);
for (int i = 0; i < n; i++) {
a[i] = inputSeq[i];
a[i] %= n;
if (a[i] == 0) {
a[i] = n;
}
}
for (int i = 1; i < n; i++) {
if (a[i] % n != (a[i - 1] + 1) % n) {
return 0;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vector<pair<int, int>> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
a[i] = {gondolaSeq[i], i};
}
vector<int> val(n);
gondolaSeq[0] %= n;
if (gondolaSeq[0] == 0) gondolaSeq[0] = n;
for (int i = 0; i < n; i++) {
if (gondolaSeq[i] <= n) {
val[i] = gondolaSeq[i];
for (int j = i - 1; j >= 0; j--) {
val[j] = val[j + 1] - 1;
if (val[j] == 0) {
val[j] = n;
}
}
for (int j = i + 1; j < n; j++) {
val[j] = val[j - 1] + 1;
if (val[j] == n + 1) {
val[j] = 1;
}
}
}
break;
}
sort(a.begin(), a.end());
int j = 0, res = 0, x = n;
for (auto [k, i] : a) {
int y = val[i];
bool first = 1;
while (k > x) {
res++;
if (first) {
first = 0;
replacementSeq[j++] = val[i];
}
else {
replacementSeq[j++] = x;
}
x++;
}
}
return res;
}
int countReplacement(int n, int inputSeq[]) {
return 0;
}