Submission #16217

#TimeUsernameProblemLanguageResultExecution timeMemory
16217CodingBugGondola (IOI14_gondola)C++98
100 / 100
89 ms6936 KiB
#include "gondola.h" #include <vector> #include <stdio.h> #include <algorithm> #include <set> #define LMT 1000000009 using namespace std; int valid(int n, int inputSeq[]) { int i,p; set<int> ch; ch.clear(); for(i=0;i<n;i++){ if(ch.find(inputSeq[i])!=ch.end()) return 0; ch.insert(inputSeq[i]); } for(i=0;i<n;i++) if(inputSeq[i]<=n) break; p=inputSeq[i]; for(;i<n;i++,p++) if(inputSeq[i]<=n && inputSeq[i]!=(p-1)%n+1) return 0; return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int i,p,l; vector<pair<int,int> > v; for(i=0;i<n;i++) if(gondolaSeq[i]>n) v.push_back(make_pair(gondolaSeq[i],i)); sort(v.begin(),v.end()); for(i=0;i<n;i++) if(gondolaSeq[i]<=n) break; if(i==n) gondolaSeq[i=0]=1; for(p=1;p<n;p++) gondolaSeq[(p+i)%n]=(gondolaSeq[i]+p-1)%n+1; for(i=n+1,p=0,l=0;p<v.size();i++){ replacementSeq[l++]=gondolaSeq[v[p].second]; gondolaSeq[v[p].second]=i; if(v[p].first==i) p++; } return l; } //---------------------- int mpow(int x,int y){ if(!y) return 1; int k=mpow(x,y/2); if(y&1) return (long long)((long long)k*k%LMT)*x%LMT; else return (long long)k*k%LMT; } int countReplacement(int n, int inputSeq[]) { if(!valid(n,inputSeq)) return 0; int i,p,s=n; vector<int> v; for(i=0;i<n;i++) if(inputSeq[i]>n) v.push_back(inputSeq[i]); for(i=0;i<n;i++) if(inputSeq[i]<=n) s=1; v.push_back(n); sort(v.begin(),v.end()); for(i=1;i<v.size();i++) s=(long long)s*mpow(((int)v.size()-i),(v[i]-v[i-1]-1))%LMT; return s; }
#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...