# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320113 | tigicha | Gondola (IOI14_gondola) | C++17 | 52 ms | 6116 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 "gondola.h"
#include<bits/stdc++.h>
using namespace std;
long long k, l, b[100005], sum, mod=1000000009;
map <long long,long long> mp;
vector<pair<int, int> >v;
vector<int>vec;
long long pow(long long x, long long y){
long long s=1;
while(y>0){
if(y%2==1) s=(s*x)%mod;
x=(x*x)%mod;
y/=2;
}
return s;
}
int valid(int n, int a[]){
l=-1;
for(int i=0; i<n; i++)
if(mp[a[i]]==1) return 0;
else mp[a[i]]=1;
for(int i=0; i<n; i++)
if(a[i]<=n){
l=i;
break;
}
if(l==-1) return 1;
k=a[l];
for(int i=l; i<n; i++)
if(a[i]!=k && a[i]<=n) return 0;
else{
k++;
if(k==n+1) k=1;
}
for(int i=0; i<l; i++)
if(a[i]!=k && a[i]<=n) return 0;
else{
k++;
if(k==n+1) k-=n;
}
return 1;
}
int replacement(int n, int a[], int ans[]){
l=-1;
for(int i=0; i<n; i++)
if(a[i]<=n){
l=i;
break;
}
k=a[l];
for(int i=l; i<n; i++){
b[i]=k;
k++;
if(k==n+1) k-=n;
}
for(int i=0; i<l; i++){
b[i]=k;
k++;
if(k==n+1) k=1;
}
for(int i=0; i<n; i++)
if(a[i]>n) v.push_back({a[i], i});
sort(v.begin(), v.end());
l=n;
k=0;
for(int i=0; i<v.size(); i++)
while(b[v[i].second]<a[v[i].second]){
ans[k]=b[v[i].second];
k++;
l++;
b[v[i].second]=l;
}
return k;
}
int countReplacement(int n, int a[]){
if(valid(n, a)==0) return 0;
vec.push_back(n);
for(int i=0; i<n; i++)
if(a[i]>n) vec.push_back(a[i]);
sort(vec.begin(), vec.end());
sum=1;
for(int i=0; i<vec.size()-1; i++){
sum*=pow(vec.size()-i-1, vec[i+1]-vec[i]-1);
sum%=mod;
}
if(vec.size()==n+1) sum=(sum*n)%mod;
return sum;
}
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... |