# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430977 | errorgorn | 곤돌라 (IOI14_gondola) | C++17 | 42 ms | 6244 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 <unordered_set>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD=1000000009;
long long qexp(long long i,long long j){
long long res=1;
while (j){
if (j&1) res=(res*i)%MOD;
i=(i*i)%MOD;
j>>=1;
}
return res;
}
int valid(int n, int in[]) {
unordered_set<int> s;
for (int x=0;x<n;x++){
s.insert(in[x]);
}
if (s.size()!=n) return 0;
int pos;
for (int x=0;x<n;x++){
if (in[x]<=n){
pos=x;
break;
}
}
for (int x=0;x<n;x++){
if (in[x]<=n && (in[x]-in[pos]+n)%n!=x-pos) return 0;
}
return 1;
}
int replacement(int n, int in[], int res[]) {
int ret=-1;
int index=-1;
int pos=0;
for (int x=0;x<n;x++){
if (in[x]<=n){
pos=(in[x]-x+n-1)%n;
break;
}
}
for (int x=0;x<n;x++){
if (in[x]>n){
res[in[x]-n-1]=(x+pos)%n+1;
}
if (in[x]>ret){
ret=in[x];
index=x;
}
}
index=(index+pos)%n+1;
for (int x=0;x<ret-n;x++){
if (res[x]==0){
res[x]=index;
index=x+n+1;
}
}
if (ret-n>=0) res[ret-n-1]=index;
return ret-n;
}
int countReplacement(int n, int in[]) {
if (!valid(n,in)) return 0;
vector<int> v;
long long ans=1;
v.push_back(n);
for (int x=0;x<n;x++){
if (in[x]>n) v.push_back(in[x]);
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for (int x=1;x<v.size();x++){
ans=(ans*qexp(x,v[x-1]-v[x]-1))%MOD;
}
for (int x=0;x<n;x++) if (in[x]<=n) return ans;
return (ans*n)%MOD;
}
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... |