#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int N=250055;
int a[N];
int b[N];
int valid(int n, int inputSeq[])
{
int j=0,x=1e9;
for(int i=0;i<n;i++)
{
a[inputSeq[i]]++;
if(x>inputSeq[i])
{
x=inputSeq[i];
j=i;
}
if(a[inputSeq[i]]>1)
return 0;
}
x++;
for(int i=j+1;i<n;i++)
{
if(inputSeq[i]<=n)
{
if(inputSeq[i]==x)
{
x++;
continue ;
}
return 0;
}
if(x>n)
x=1;
if(a[x]==0)
x++;
else
return 0;
}
if(x>n)
x=1;
for(int i=0;i<j;i++)
{
if(inputSeq[i]<=n)
{
if(inputSeq[i]==x)
{
x++;
continue ;
}
return 0;
}
if(a[x]==0)
x++;
else
return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
bool q=0;
for(int i=0;i<n;i++)
{
a[gondolaSeq[i]]=i+1;
if(!q&&gondolaSeq[i]<=n)
{
q=1;
int x=gondolaSeq[i];
for(int j=i;j<n;j++)
{
b[j]=x;
x++;
if(x>n)
x=1;
}
for(int j=0;j<i;j++)
{
b[j]=x++;
if(x>n)
x=1;
}
}
}
if(!q)
for(int i=0;i<n;i++)
b[i]=i+1;
int x=n+1;
int j=0;
for(int i=n+1;i<N;i++)
{
if(!a[i])
continue ;
a[i]--;
while(b[a[i]]!=i)
{
replacementSeq[j++]=b[a[i]];
b[a[i]]=x;
x++;
}
}
return j;
}
int m=1e9+9;
long long pow(long long x, int i)
{
if(i%2)
return (pow(x,i-1)*x)%m;
if(i==0)
return 1;
long long y=pow(x,i/2)%m;
return (y*y)%m;
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq))
return 0;
bool q=0;
memset(a,0,sizeof a);
for(int i=0;i<n;i++)
a[inputSeq[i]]=i+1;
if(!q)
for(int i=0;i<n;i++)
b[i]=i+1;
int x=n+1;
long long ans=1;
long long cnt=0;
for(int i=n+1;i<N;i++)
if(a[i])
cnt++;
int last=n;
for(int i=n+1;i<N;i++)
{
if(!a[i]||cnt==0)
continue ;
a[i]--;
ans*=pow(cnt,(inputSeq[a[i]]-last)-1);
ans%=m;
last=inputSeq[a[i]];
cnt--;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:137:9: warning: unused variable 'x' [-Wunused-variable]
int x=n+1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
480 KB |
Output is correct |
4 |
Correct |
3 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
712 KB |
Output is correct |
5 |
Correct |
2 ms |
712 KB |
Output is correct |
6 |
Correct |
7 ms |
876 KB |
Output is correct |
7 |
Correct |
14 ms |
1260 KB |
Output is correct |
8 |
Correct |
14 ms |
1260 KB |
Output is correct |
9 |
Correct |
7 ms |
1260 KB |
Output is correct |
10 |
Correct |
13 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1260 KB |
Output is correct |
2 |
Correct |
3 ms |
1260 KB |
Output is correct |
3 |
Correct |
2 ms |
1260 KB |
Output is correct |
4 |
Correct |
2 ms |
1260 KB |
Output is correct |
5 |
Correct |
2 ms |
1260 KB |
Output is correct |
6 |
Correct |
9 ms |
1260 KB |
Output is correct |
7 |
Correct |
17 ms |
1372 KB |
Output is correct |
8 |
Correct |
10 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
14 ms |
1372 KB |
Output is correct |
11 |
Correct |
2 ms |
1372 KB |
Output is correct |
12 |
Correct |
3 ms |
1372 KB |
Output is correct |
13 |
Correct |
10 ms |
1532 KB |
Output is correct |
14 |
Correct |
2 ms |
1532 KB |
Output is correct |
15 |
Correct |
17 ms |
1532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1532 KB |
Output is correct |
2 |
Correct |
3 ms |
1532 KB |
Output is correct |
3 |
Correct |
3 ms |
1532 KB |
Output is correct |
4 |
Correct |
2 ms |
1532 KB |
Output is correct |
5 |
Correct |
3 ms |
1532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1532 KB |
Output is correct |
2 |
Correct |
2 ms |
1532 KB |
Output is correct |
3 |
Correct |
3 ms |
1532 KB |
Output is correct |
4 |
Correct |
4 ms |
1532 KB |
Output is correct |
5 |
Correct |
2 ms |
1532 KB |
Output is correct |
6 |
Correct |
3 ms |
1532 KB |
Output is correct |
7 |
Correct |
3 ms |
1532 KB |
Output is correct |
8 |
Correct |
3 ms |
1532 KB |
Output is correct |
9 |
Correct |
4 ms |
1532 KB |
Output is correct |
10 |
Correct |
3 ms |
1532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1532 KB |
Output is correct |
2 |
Correct |
3 ms |
1532 KB |
Output is correct |
3 |
Correct |
4 ms |
1532 KB |
Output is correct |
4 |
Correct |
3 ms |
1532 KB |
Output is correct |
5 |
Correct |
3 ms |
1532 KB |
Output is correct |
6 |
Correct |
4 ms |
1532 KB |
Output is correct |
7 |
Correct |
3 ms |
1532 KB |
Output is correct |
8 |
Correct |
3 ms |
1532 KB |
Output is correct |
9 |
Correct |
3 ms |
1532 KB |
Output is correct |
10 |
Correct |
4 ms |
1532 KB |
Output is correct |
11 |
Correct |
13 ms |
1580 KB |
Output is correct |
12 |
Correct |
14 ms |
1708 KB |
Output is correct |
13 |
Correct |
20 ms |
1968 KB |
Output is correct |
14 |
Correct |
13 ms |
1968 KB |
Output is correct |
15 |
Correct |
23 ms |
2988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2988 KB |
Output is correct |
2 |
Correct |
3 ms |
2988 KB |
Output is correct |
3 |
Correct |
4 ms |
2988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2988 KB |
Output is correct |
2 |
Correct |
3 ms |
2988 KB |
Output is correct |
3 |
Correct |
5 ms |
2988 KB |
Output is correct |
4 |
Correct |
3 ms |
2988 KB |
Output is correct |
5 |
Correct |
4 ms |
2988 KB |
Output is correct |
6 |
Correct |
3 ms |
2988 KB |
Output is correct |
7 |
Correct |
4 ms |
2988 KB |
Output is correct |
8 |
Correct |
4 ms |
2988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2988 KB |
Output is correct |
2 |
Correct |
4 ms |
2988 KB |
Output is correct |
3 |
Correct |
4 ms |
2988 KB |
Output is correct |
4 |
Correct |
5 ms |
2988 KB |
Output is correct |
5 |
Correct |
4 ms |
2988 KB |
Output is correct |
6 |
Correct |
5 ms |
2988 KB |
Output is correct |
7 |
Correct |
5 ms |
2988 KB |
Output is correct |
8 |
Correct |
4 ms |
2988 KB |
Output is correct |
9 |
Correct |
20 ms |
2988 KB |
Output is correct |
10 |
Correct |
15 ms |
2988 KB |
Output is correct |
11 |
Correct |
9 ms |
2988 KB |
Output is correct |
12 |
Correct |
11 ms |
2988 KB |
Output is correct |
13 |
Incorrect |
5 ms |
2988 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2988 KB |
Output is correct |
2 |
Correct |
4 ms |
2988 KB |
Output is correct |
3 |
Correct |
4 ms |
2988 KB |
Output is correct |
4 |
Correct |
3 ms |
2988 KB |
Output is correct |
5 |
Correct |
4 ms |
2988 KB |
Output is correct |
6 |
Correct |
5 ms |
2988 KB |
Output is correct |
7 |
Correct |
4 ms |
2988 KB |
Output is correct |
8 |
Correct |
3 ms |
2988 KB |
Output is correct |
9 |
Correct |
23 ms |
2988 KB |
Output is correct |
10 |
Correct |
16 ms |
2988 KB |
Output is correct |
11 |
Correct |
8 ms |
2988 KB |
Output is correct |
12 |
Correct |
11 ms |
2988 KB |
Output is correct |
13 |
Incorrect |
6 ms |
2988 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |