# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
379820 | ponytail | Gondola (IOI14_gondola) | C++17 | 40 ms | 4716 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 fi first
#define se second
#define pb push_back
using namespace std;
const int MOD = 1e9 + 9; // remember to long long
int valid(int n,int inputSeq[]){
int cnt=0;
set<int>s;
for(int i=0;i<n;i++) s.insert(inputSeq[i]);
for(int i=0;i<n;i++)cnt+=(inputSeq[i]>=1&&inputSeq[i]<=n);
if(s.size()!=n) return 0;
if(cnt==0) return 1;
for(int i=0;i<n;i++){
if(inputSeq[i]>=1 && inputSeq[i]<=n){
int now=inputSeq[i];
for(int j=i;j<i+n;j++){
if(now!=inputSeq[j%n] && inputSeq[j%n]>=1 && inputSeq[j%n]<=n){
return 0;
}
now=now%n+1;
}
return 1;
}
}
}
int replacement(int n,int gondolaSeq[],int replacementSeq[]){
int cnt=0, maxel=0;
for(int i=0;i<n;i++){
cnt+=(gondolaSeq[i]>=1 && gondolaSeq[i]<=n);
maxel=max(maxel,gondolaSeq[i]);
}
int l=maxel-n;
if(cnt==0){
pair<int,int>gs[n];
for(int i=0;i<n;i++) gs[i]={gondolaSeq[i],i};
sort(gs,gs+n);
int now=0, ok=n+1;
int cur[n];
for(int i=0;i<n;i++)cur[i]=i+1;
for(int i=0;i<n;i++){
for(;ok<=gs[i].fi;ok++){
replacementSeq[now++]=cur[gs[i].se];
cur[gs[i].se]=ok;
}
}
return l;
}
vector<pair<int,int> >v;
for(int i=0;i<n;i++){
if(gondolaSeq[i]>n) v.pb({gondolaSeq[i],i});
}
sort(v.begin(),v.end());
int V=v.size();
int now=0, ok=n+1;
int cur[n];
for(int i=0;i<n;i++){
if(gondolaSeq[i]>=1 && gondolaSeq[i]<=n){
int now=gondolaSeq[i];
for(int j=i;j<i+n;j++){
cur[j%n]=now;
now=now%n+1;
}
break;
}
}
for(int i=0;i<V;i++){
for(;ok<=v[i].fi;ok++){
replacementSeq[now++]=cur[v[i].se];
cur[v[i].se]=ok;
}
}
return l;
}
int countReplacement(int n,int inputSeq[]){
}
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... |