Submission #292794

#TimeUsernameProblemLanguageResultExecution timeMemory
292794TMJNGondola (IOI14_gondola)C++17
100 / 100
32 ms2688 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]){ int t=1; for(int i=0;i<n;i++){ if(inputSeq[i]<=n){ for(int j=0;j<n;j++){ if(inputSeq[(i+j)%n]<=n){ if((inputSeq[i]+j)%n!=inputSeq[(i+j)%n]%n){ t=0; } } } break; } } sort(inputSeq,inputSeq+n); for(int i=0;i<n-1;i++){ if(inputSeq[i]==inputSeq[i+1])t=0; } return t; } int K[100000],P[250001]; int replacement(int n, int gondolaSeq[], int replacementSeq[]){ int mx=0; for(int i=0;i<n;i++){ mx=max(mx,gondolaSeq[i]); } for(int i=0;i<n;i++){ K[i]=i+1; } for(int i=0;i<n;i++){ if(gondolaSeq[i]<=n){ for(int j=0;j<n;j++){ K[(i+j)%n]=(gondolaSeq[i]+j)%n; } for(int j=0;j<n;j++){ if(!K[j])K[j]=n; } break; } } for(int i=0;i<n;i++){ P[gondolaSeq[i]]=K[i]; } for(int i=0;i<n;i++){ if(gondolaSeq[i]==mx){ int c=0; int t=K[i]; for(int j=n+1;j<=mx-1;j++){ if(!P[j]){ replacementSeq[c]=t; t=j; } else{ replacementSeq[c]=P[j]; } c++; } replacementSeq[c]=t; } } return mx-n; } long long pw(long long x,int y){ long long a=1; while(y){ if(y&1)a=a*x%1000000009; x=x*x%1000000009; y/=2; } return a; } int countReplacement(int n, int inputSeq[]){ if(!valid(n,inputSeq))return 0; long long k; if(inputSeq[0]<=n)k=1; else k=n; int p=n; for(int i=0;i<n;i++){ if(inputSeq[i]<=p)continue; k*=pw(n-i,inputSeq[i]-p-1); k%=1000000009; p=inputSeq[i]; } return k; }
#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...