Submission #563225

#TimeUsernameProblemLanguageResultExecution timeMemory
563225shahriarkhanGondola (IOI14_gondola)C++14
60 / 100
39 ms4576 KiB
#include "gondola.h" #include<bits/stdc++.h> using namespace std ; const long long mod = 1e9 + 7 ; long long power(long long a , long long p) { long long ret = 1 ; while(p) { if(p&1) ret = (ret*a)%mod ; a = (a*a)%mod ; p >>= 1 ; } return ret ; } int valid(int n, int inputSeq[]) { int idx = -1 , cur = 0 ; map<int,int> vis ; for(int i = 0 ; i < n ; ++i) { if(vis.find(inputSeq[i])!=vis.end()) return 0 ; vis[inputSeq[i]] = 1 ; } for(int i = 0 ; i < n ; ++i) { if(inputSeq[i]<=n) { idx = i ; cur = inputSeq[i] - 1 ; break ; } } if(idx<0) return 1 ; for(int i = idx ; i < n ; ++i) { if((inputSeq[i]<=n) && (inputSeq[i]!=(cur+1))) return 0 ; cur = (cur+1)%n ; } return 1 ; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector<pair<int,int> > v ; vector<int> ans ; int cur = 0 , idx = 0 ; for(int i = 0 ; i < n ; ++i) { if(gondolaSeq[i]<=n) { idx = i ; cur = gondolaSeq[i] - 1 ; break ; } } for(int i = idx ; i < n ; ++i) { if(gondolaSeq[i]>n) { v.push_back({gondolaSeq[i],cur+1}) ; } cur = (cur+1)%n ; } for(int i = 0 ; i < idx ; ++i) { if(gondolaSeq[i]>n) { v.push_back({gondolaSeq[i],cur+1}) ; } cur = (cur+1)%n ; } sort(v.begin(),v.end()) ; cur = n ; for(pair<int,int> p : v) { ans.push_back(p.second) , ++cur ; while(cur<p.first) { ans.push_back(cur) ; ++cur ; } } int siz = ans.size() ; for(int i = 0 ; i < siz ; ++i) { replacementSeq[i] = ans[i] ; } return siz ; } int countReplacement(int n, int inputSeq[]) { long long ans = 1 , mul = n ; if(!valid(n,inputSeq)) return 0 ; long long a[n+2] = {0} , siz = 0 ; for(int i = 0 ; i < n ; ++i) { if(inputSeq[i]<=n) { mul = 1 ; continue ; } a[++siz] = inputSeq[i] ; } sort(a+1,a+siz+1) ; a[0] = n ; for(int i = 1 ; i <= siz ; ++i) { long long cur = power(siz-i+1,a[i]-a[i-1]-1) ; ans = (ans*cur)%mod ; } return (ans*mul)%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...