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 <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <utility>
#ifndef LOCAL
#include "gondola.h"
#endif
template <class T>
using Vec = std::vector<T>;
void fix(int n, int seq[]) {
for (int i = 0; i < n; ++i) {
seq[i] -= 1;
}
}
int valid(int n, int inputSeq[]) {
fix(n, inputSeq);
Vec<int> rep;
for (int i = 0; i < n; ++i) {
if (inputSeq[i] >= n) {
rep.push_back(inputSeq[i]);
}
}
if (!rep.empty()) {
std::sort(rep.begin(), rep.end());
if (std::unique(rep.begin(), rep.end()) != rep.end()) {
return 0;
}
}
for (int i = 0; i < n; ++i) {
if (inputSeq[i] < n) {
for (int j = 0; j < n; ++j) {
const auto x = inputSeq[(i + j) % n];
if (x < n && x != (inputSeq[i] + j) % n) {
return 0;
}
}
return 1;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
fix(n, gondolaSeq);
Vec<int> index(n);
std::iota(index.begin(), index.end(), 0);
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] < n) {
for (int j = 0; j < n; ++j) {
index[(i + j) % n] = (gondolaSeq[i] + j) % n;
}
break;
}
}
Vec<std::pair<int, int>> change;
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] >= n) {
change.emplace_back(gondolaSeq[i], index[i]);
}
}
std::sort(change.begin(), change.end());
int rep = n;
int size = 0;
for (const auto [last, first]: change) {
replacementSeq[size++] = first + 1;
while (rep < last) {
replacementSeq[size++] = rep++ + 1;
}
rep = last + 1;
}
return size;
}
int countReplacement(int n, int inputSeq[]) {
fix(n, inputSeq);
if (!valid(n, inputSeq)) {
return 0;
}
return 0;
}
#ifdef LOCAL
int main() {
int n;
std::cin >> n;
int seq[100] = {};
for (int i = 0; i < n; ++i) {
std::cin >> seq[i];
}
int rep[100] = {};
int size = replacement(n, seq, rep);
for (int i = 0; i < size; ++i) {
std::cout << rep[i] << '\n';
}
return 0;
}
#endif
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |