# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
508853 | tabr | 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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int valid(int n, int s[]) {
set<int> st;
for (int i = 0; i < n; i++) {
if (st.count(s[i])) {
return 0;
}
st.emplace(s[i]);
}
int pos = -1;
for (int i = 0; i < n; i++) {
if (s[i] <= n) {
pos = (i - s[i] + 1 + n) % n;
break;
}
}
for (int i = 0; i < n; i++) {
if (s[i] <= n) {
if (pos != (i - s[i] + 1 + n) % n) {
return 0;
}
}
}
return 1;
}
int replacement(int n, int s[], int res[]) {
int pos = -1;
for (int i = 0; i < n; i++) {
if (s[i] <= n) {
pos = (i - s[i] + 1 + n) % n;
}
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) { return s[i] < s[j]; });
int id = 0;
int lst = n;
for (int i : order) {
if (s[i] <= n) {
continue;
}
int j = (i - pos + n) % n + 1;
res[id++] = j;
for (int x = lst + 2; x <= s[i]; x++) {
res[id++] = x - 1;
}
lst = s[i];
}
return id;
}