Submission #1304233

#TimeUsernameProblemLanguageResultExecution timeMemory
1304233activedeltorreGondola (IOI14_gondola)C++20
90 / 100
51 ms11336 KiB
#include "gondola.h" #include<map> using namespace std; map<int,int>fre; int valid(int n, int inputSeq[]) { int offset=-1,val,off2; fre.clear(); for(int i=1; i<=n; i++) { val=inputSeq[i-1]; fre[val]++; if(fre[val]>=2) { return 0; } if(val<=0) { return 0; } if(val<=n && offset==-1) { offset=(i-val+n)%n; } else if(val<=n) { off2=(i-val+n)%n; if(off2!=offset) { return 0; } } } return 1; } //---------------------- int v[100005]; int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int valmax=0,val,pozmax=0,offset=-1; fre.clear(); for(int i=1; i<=n; i++) { val=gondolaSeq[i-1]; fre[val]=i; valmax=max(valmax,val); if(val<=n && offset==-1) { offset=(i-val+n)%n; } if(val==valmax) { pozmax=i; } } for(int i=1; i<=n; i++) { v[i]=(i-offset+n-1)%n+1; } for(int i=n+1; i<=valmax; i++) { if(fre[i]==0) { replacementSeq[i-n-1]=v[pozmax]; v[pozmax]=i; } else { replacementSeq[i-n-1]=v[fre[i]]; v[fre[i]]=i; } } return valmax-n; } //---------------------- int spar[300005]; int countReplacement(int n, int inputSeq[]) { int valmax=0,val,pozmax=0,offset=-1; fre.clear(); if(valid(n,inputSeq)==0) { return 0; } for(int i=1; i<=n; i++) { val=inputSeq[i-1]; fre[val]=i; valmax=max(valmax,val); if(val<=n && offset==-1) { offset=(i-val+n)%n; } if(val>n) { spar[n+1]++; spar[val]--; } } long long prod=1; if(offset==-1) { prod=n; } long long mod=1e9+9; for(int i=n+1; i<=valmax; i++) { spar[i]=spar[i]+spar[i-1]; if(fre[i]==0) { prod=(prod*spar[i])%mod; } } return prod%mod; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...