#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int valid(int n, int seq[])
{
map<int,int> mp;
bool ch=true;
int temp=-1;
for(int i=0;i<n;i++)
{
if(seq[i]<=n)
{
if(ch)
{
ch=false;
temp=(seq[i]-i+n)%n;
}
else if((seq[i]-i+n)%n!=temp) return 0;
}
if(mp[seq[i]]) return 0;
else mp[seq[i]]=1;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int ma=-1;
for(int i=0;i<n;i++) ma=max(gondolaSeq[i],ma);
int permu=1;
for(int i=0;i<n;i++)
{
if(gondolaSeq[i]<=n)
{
permu=(gondolaSeq[i]-i+n)%n;
}
}
int gondo[250010]={};
for(int i=0;i<n;i++) gondo[gondolaSeq[i]]=(i+n-1+permu)%n+1;
int onpath[250010]={};
for(int i=1;i<=n;i++) onpath[i]=i;
int temp=gondo[ma];
for(int i=n+1;i<=ma;i++)
{
if(gondo[i])
{
replacementSeq[i-n-1]=onpath[gondo[i]];
onpath[gondo[i]]=i;
}
else
{
replacementSeq[i-n-1]=onpath[temp];
onpath[temp]=i;
}
}
return ma-n;
}
//----------------------
ll big=1000000009;
ll expo(int x,int y)
{
if(y==0) return 1ll;
if(y==1) return (long long)x;
if(y&1) return ((((expo(x,y>>1))*(expo(x,y>>1)))%big)*(long long)x)%big;
return ((expo(x,y>>1))*(expo(x,y>>1)))%big;
}
int countReplacement(int n, int inputSeq[])
{
ll res=1;
if(!valid(n,inputSeq)) return 0;
bool ch=false;
int ti[n];
for(int i=0;i<n;i++)
{
ti[i]=inputSeq[i];
if(ti[i]<=n) ch=true;
}
sort(ti,ti+n);
for(int i=n-1;i>=0;i--)
{
if(ti[i]<=n) break;
if(i) res*=expo(n-i,ti[i]-max(ti[i-1],n)-1);
else res*=expo(n,ti[0]-n-1);
res%=big;
}
if(!ch)
{
res*=(long long)n;
res%=big;
}
return (int)res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
2372 KB |
Output is correct |
7 |
Correct |
11 ms |
1060 KB |
Output is correct |
8 |
Correct |
35 ms |
4252 KB |
Output is correct |
9 |
Correct |
10 ms |
1480 KB |
Output is correct |
10 |
Correct |
37 ms |
4936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
2328 KB |
Output is correct |
7 |
Correct |
11 ms |
1056 KB |
Output is correct |
8 |
Correct |
31 ms |
4280 KB |
Output is correct |
9 |
Correct |
12 ms |
1484 KB |
Output is correct |
10 |
Correct |
38 ms |
4924 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
11 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2196 KB |
Output is correct |
2 |
Correct |
2 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
2 ms |
2224 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
2 |
Correct |
2 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
6 |
Correct |
2 ms |
2252 KB |
Output is correct |
7 |
Correct |
2 ms |
2252 KB |
Output is correct |
8 |
Correct |
3 ms |
2252 KB |
Output is correct |
9 |
Correct |
2 ms |
2252 KB |
Output is correct |
10 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
2 |
Correct |
2 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
2 ms |
2252 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
6 |
Correct |
4 ms |
2252 KB |
Output is correct |
7 |
Correct |
2 ms |
2252 KB |
Output is correct |
8 |
Correct |
2 ms |
2252 KB |
Output is correct |
9 |
Correct |
2 ms |
2252 KB |
Output is correct |
10 |
Correct |
3 ms |
2252 KB |
Output is correct |
11 |
Correct |
11 ms |
2944 KB |
Output is correct |
12 |
Correct |
13 ms |
3020 KB |
Output is correct |
13 |
Correct |
15 ms |
3184 KB |
Output is correct |
14 |
Correct |
12 ms |
2892 KB |
Output is correct |
15 |
Correct |
23 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
49 ms |
4748 KB |
Output is correct |
10 |
Correct |
38 ms |
3908 KB |
Output is correct |
11 |
Correct |
14 ms |
1612 KB |
Output is correct |
12 |
Correct |
17 ms |
1944 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
53 ms |
4872 KB |
Output is correct |
10 |
Correct |
39 ms |
3932 KB |
Output is correct |
11 |
Correct |
14 ms |
1668 KB |
Output is correct |
12 |
Correct |
17 ms |
1964 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
14 |
Correct |
64 ms |
5616 KB |
Output is correct |
15 |
Correct |
72 ms |
6268 KB |
Output is correct |
16 |
Correct |
11 ms |
1356 KB |
Output is correct |
17 |
Correct |
46 ms |
4300 KB |
Output is correct |
18 |
Correct |
24 ms |
2536 KB |
Output is correct |