#include "gondola.h"
#include<bits/stdc++.h>
using namespace std ;
const long long mod = 1e9 + 9 ;
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 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
2132 KB |
Output is correct |
7 |
Correct |
9 ms |
568 KB |
Output is correct |
8 |
Correct |
25 ms |
3848 KB |
Output is correct |
9 |
Correct |
7 ms |
1364 KB |
Output is correct |
10 |
Correct |
33 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
12 ms |
2132 KB |
Output is correct |
7 |
Correct |
8 ms |
636 KB |
Output is correct |
8 |
Correct |
24 ms |
3924 KB |
Output is correct |
9 |
Correct |
9 ms |
1340 KB |
Output is correct |
10 |
Correct |
31 ms |
4428 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
22 ms |
2036 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
48 ms |
4596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
228 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
596 KB |
Output is correct |
13 |
Correct |
14 ms |
1360 KB |
Output is correct |
14 |
Correct |
10 ms |
596 KB |
Output is correct |
15 |
Correct |
20 ms |
2256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
40 ms |
4992 KB |
Output is correct |
10 |
Correct |
32 ms |
4252 KB |
Output is correct |
11 |
Correct |
13 ms |
1712 KB |
Output is correct |
12 |
Correct |
14 ms |
2016 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
4976 KB |
Output is correct |
10 |
Correct |
33 ms |
4132 KB |
Output is correct |
11 |
Correct |
12 ms |
1768 KB |
Output is correct |
12 |
Correct |
15 ms |
1964 KB |
Output is correct |
13 |
Correct |
3 ms |
624 KB |
Output is correct |
14 |
Correct |
50 ms |
6000 KB |
Output is correct |
15 |
Correct |
61 ms |
6716 KB |
Output is correct |
16 |
Correct |
11 ms |
1508 KB |
Output is correct |
17 |
Correct |
52 ms |
4628 KB |
Output is correct |
18 |
Correct |
21 ms |
2644 KB |
Output is correct |