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>
#include "gondola.h"
using namespace std;
int valid(int n, int inputSeq[]) {
unordered_map<int, int> cnt;
for (int i = 0; i < n; ++i) cnt[inputSeq[i]]++;
if ((int)cnt.size() < n) return 0;
for (int i = 1; inputSeq[0]+i <= n; ++i) {
if (inputSeq[i] <= n && inputSeq[i] != inputSeq[0]+i) return 0;
}
for (int i = 1; inputSeq[0]-i > 0; ++i) {
if (inputSeq[n-i] <= n && inputSeq[n-i] != inputSeq[0]-i) return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vector<int> gondola(n);
int idx = -1;
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] <= n) {
gondola[i] = gondolaSeq[i];
idx = i;
break;
}
}
if (idx == -1) {
for (int i = 0; i < n; ++i) gondola[i] = i+1;
} else {
for (int i = 1; gondola[idx]+i <= n; ++i) {
gondola[(idx+i)%n] = gondola[idx]+i;
}
for (int i = 1; gondola[idx]-i > 0; ++i) {
gondola[(idx-i+n)%n] = gondola[idx]-i;
}
}
vector<pair<int, int>> replacements;
replacements.reserve(n);
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] != gondola[i]) replacements.push_back({gondolaSeq[i], gondola[i]});
}
sort(replacements.begin(), replacements.end());
int l = 0, new_gondola = n+1;
for (pair<int, int> p: replacements) {
while (p.first > new_gondola) {
replacementSeq[l] = p.second;
p.second = new_gondola;
++new_gondola; ++l;
}
replacementSeq[l] = p.second;
++new_gondola;
++l;
}
return l;
}
int countReplacement(int n, int inputSeq[]) {
return 0;
}
# | 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... |