# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
355610 | Mefarnis | Gondola (IOI14_gondola) | C++14 | 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>
#include "gondola.h"
#define maxn 100003
#define maxv 250001
using namespace std;
int idx[maxn];
int init[maxn];
void calcInit(int n, int inputSeq[], int minIdx) {
if(minIdx == -1)
for( int i = 0 ; i < n ; i++ )
init[i] = i+1;
else
for( int i = 0 ; i < n ; i++ ) {
int d = (i-minIdx+n) % n;
init[i] = inputSeq[minIdx]+d
}
}
int valid(int n, int inputSeq[]) {
int minIdx = -1;
set<int> s;
for( int i = 0 ; i < n ; i++ ) {
if(s.find(inputSeq[i]) != s.end())
return 0;
s.insert(inputSeq[i]);
if(inputSeq[i] <= n) {
if(minIdx == -1 || inputSeq[i] < inputSeq[minIdx])
minIdx = i;
}
}
calcInit(n,inputSeq,minIdx);
if(minIdx == -1)
return 1;
for( int i = 0 ; i < n ; i++ )
if(inputSeq[i] <= n) {
if(init[i] != inputSeq[i])
return 0;
}
return 1;
}
int replacement(int n, int inputSeq[], int replacementSeq[]) {
if(!valid(n,inputSeq))
return 0;
int maxIdx = -1;
memset(idx,-1,sizeof(idx));
for( int i = 0 ; i < n ; i++ ) {
idx[inputSeq[i]] = i;
if(maxIdx == -1 || inputSeq[i] > inputSeq[maxIdx])
maxIdx = i;
}
int cnt = 0;
int curr = init[maxIdx];
int maxVal = inputSeq[maxIdx];
for( int i = n+1 ; i <= maxVal ; i++ ) {
if(idx[i] == -1)
replacementSeq[cnt++] = curr++;
else
replacementSeq[cnt++] = init[idx[i]];
}
return cnt;
}
int countReplacement(int n, int inputSeq[]) {
return -3;
}