# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019151 | presko | Gondola (IOI14_gondola) | C++14 | 13 ms | 2520 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<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include "gondola.h"
#define MAXN 300010
using namespace std;
bool used[MAXN];
int valid(int n, int inputSeq[])
{
for(int i=0;i<n;i++)
{
if(used[inputSeq[i]])return 0;
used[inputSeq[i]]=1;
if(inputSeq[i]<=n)
{
int prev=i-1,valp=inputSeq[i]-1;
if(prev<0)prev=n-1;
if(valp<1)valp=n;
int next=i+1,valn=inputSeq[i]+1;
if(next>=n)next=0;
if(valn>n)valn=1;
if(inputSeq[prev]<=n && inputSeq[prev]!=valp)return 0;
if(inputSeq[next]<=n && inputSeq[next]!=valn)return 0;
}
}
return 1;
}
//----------------------
vector<pair<int,int>> order;
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int ans=0,pos=-1;
for(int i=0;i<n;i++)if(gondolaSeq[i]<=n){pos=i;break;}
if(pos==-1)for(int i=0;i<n;i++)order.push_back({gondolaSeq[i],i+1});
else
{
int curr=gondolaSeq[pos];
for(int i=pos-1;i>=0;i--)
{
curr--;
if(curr==0)curr=n;
if(gondolaSeq[i]>n)order.push_back({gondolaSeq[i],curr});
gondolaSeq[i]=curr;
}
for(int i=n-1;i>pos;i--)
{
curr--;
if(curr==0)curr=n;
if(gondolaSeq[i]>n)order.push_back({gondolaSeq[i],curr});
gondolaSeq[i]=curr;
}
}
sort(order.begin(),order.end());
int last=n;
for(int i=0;i<order.size();i++)
{
int ind=order[i].first;
int frst=order[i].second;
replacementSeq[ans++]=frst;
for(int j=last+2;j<=ind;j++)
{
replacementSeq[ans++]=j-1;
}
last=ind;
}
return ans;
}
//----------------------
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... |