# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376780 | lakshith_ | 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 "gondola.h"
#include <bits/stdc++.h>
using namespace std;
bool b[2500010];
int checkOnce(int n,int vec[]){
for(int i=0;i<n;i++)
if(b[vec[i]])return 0;
else b[vec[i]]=true;
return 1;
}
int valid(int n, int vec[])
{
if(!checkOnce(n,vec))return 0;
int MIN=INT_MAX,minI=0;
for(int i=0;i<n;i++)if(MIN>vec[i])MIN=vec[i],minI=i;
int p = MIN;
int pos = minI;
if(MIN>n)return 1;
for(int k=0;k<n;k++){
if(vec[pos]<=n && vec[pos]!=p)return 0;
pos++;
p++;
pos%=n;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int start = 0;
for(int i=0;i<n;i++){
if(gondolaSeq[i]<=n){start = i;break;}
}
int next = gondolaSeq[start]<=n?gondolaSeq[start]:1;
vector<pair<int,int>> vec;
int pos = start;
for(int i=0;i<n;i++){
x[i] = {gondolaSeq[pos],next};
pos++;
next++;
if(next>n)next = 1;
if(pos>=n)pos=0;
}
sort(x,x+n);
int last = n;
int l = 0;
for(int i=0;i<n;i++){
while(x[i].first != x[i].second){
replacementSeq[l++] = x[i].second;
x[i].second = ++last;
}
}
return l;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}