# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588890 | snasibov05 | Gondola (IOI14_gondola) | C++14 | 35 ms | 4728 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 "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
int mni = 0;
set<int> st;
for (int i = 0; i < n; ++i){
st.insert(inputSeq[i]);
if (inputSeq[i] < inputSeq[mni]) mni = i;
}
if (st.size() < n) return 0;
if (inputSeq[mni] > n) return 1;
int k = mni - 1, x = inputSeq[mni] - 1;
while (x > 0) {
if (k == -1) k = n-1;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
inputSeq[k] = x;
k--, x--;
}
k = mni + 1, x = inputSeq[mni] + 1;
while (x <= n){
if (k == n) k = 0;
if (inputSeq[k] != x && inputSeq[k] <= n) return 0;
inputSeq[k] = x;
k++, x++;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int mni = 0, mxi = 0;
for (int i = 0; i < n; ++i){
if (gondolaSeq[i] < gondolaSeq[mni]) mni = i;
if (gondolaSeq[i] > gondolaSeq[mxi]) mxi = i;
}
if (gondolaSeq[mxi] <= n) return 0;
vector<int> v(n);
if (gondolaSeq[mni] <= n){
v[mni] = gondolaSeq[mni];
int k = mni - 1, x = gondolaSeq[mni] - 1;
while (x > 0) {
if (k == -1) k = n-1;
v[k] = x;
k--, x--;
}
k = mni + 1, x = gondolaSeq[mni] + 1;
while (x <= n){
if (k == n) k = 0;
v[k] = x;
k++, x++;
}
} else{
for (int i = 0; i < n; ++i) v[i] = i+1;
}
vector<pair<int, int>> arr;
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] <= n) continue;
arr.push_back({gondolaSeq[i], i});
}
sort(arr.begin(), arr.end());
int l = 0;
for (int i = 0; i < arr.size(); ++i){
int k;
if (i == 0) k = n+1;
else k = arr[i-1].first + 1;
while (k < arr[i].first) {
replacementSeq[l] = v[mxi];
v[mxi] = k;
l++, k++;
}
replacementSeq[l] = v[arr[i].second];
v[arr[i].second] = arr[i].first;
l++;
}
return l;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
Compilation message (stderr)
# | 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... |