#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
using ll = long long;
const ll mod = 1000000009;
ll modPow(ll a,ll b,ll c){
ll r=1;
while(b){
if(b&1) (r*=a)%=c;
(a*=a)%=c;
b/=2;
}
return r;
}
int valid(int n, int inputSeq[]){
for(int i=0;i<n;i++) inputSeq[i]--;
set<int> s;
for(int i=0;i<n;i++) s.insert(inputSeq[i]);
if(s.size()!=n) return 0;
for(int i=0;i<n;i++){
if(inputSeq[i]<n){
for(int j=0;j<n;j++){
if(inputSeq[(i+j)%n]<n&&inputSeq[(i+j)%n]!=(inputSeq[i]+j)%n) return 0;
}
return 1;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
for(int i=0;i<n;i++) gondolaSeq[i]--;
int m=0;
for(int i=0;i<n;i++) m=max(m,gondolaSeq[i]);
vector<int> gon(n);
int v=0;
for(int i=0;i<n;i++){
if(gondolaSeq[i]<n){
v=(i-gondolaSeq[i]+n)%n;
}
}
for(int i=0;i<n;i++) gon[(i+v)%n]=i;
vector<int> rev(500000,-1);
for(int i=0;i<n;i++) rev[gondolaSeq[i]]=i;
set<int> idx;
for(int i=0;i<n;i++){
if(gondolaSeq[i]>=n) idx.insert(i);
}
for(int i=n;i<=m;i++){
if(rev[i]==-1){
int id=(*idx.begin());
replacementSeq[i-n]=gon[id]+1;
gon[id]=i;
}
else{
replacementSeq[i-n]=gon[rev[i]]+1;
idx.erase(rev[i]);
gon[rev[i]]=i;
}
}
return m-n+1;
}
int countReplacement(int n, int inputSeq[]){
for(int i=0;i<n;i++) inputSeq[i]--;
bool ok=true;
set<int> s;
for(int i=0;i<n;i++) s.insert(inputSeq[i]);
if(s.size()!=n) ok=false;
for(int i=0;i<n;i++){
if(inputSeq[i]<n){
for(int j=0;j<n;j++){
if(inputSeq[(i+j)%n]<n&&inputSeq[(i+j)%n]!=(inputSeq[i]+j)%n) ok=false;
}
break;
}
}
if(!ok) return 0;
int m=0;
for(int i=0;i<n;i++) m=max(m,inputSeq[i]);
vector<int> gon(n);
int v=0;
ll c=n;
for(int i=0;i<n;i++){
if(inputSeq[i]<n){
c=1;
v=(i-inputSeq[i]+n)%n;
}
}
ll ans=1;
for(int i=0;i<n;i++) gon[(i+v)%n]=i;
set<int> idx;
for(int i=0;i<n;i++){
if(inputSeq[i]>=n) idx.insert(i);
}
vector<int> id;
id.push_back(n-1);
for(int i=0;i<n;i++){
if(inputSeq[i]>=n) id.push_back(inputSeq[i]);
}
sort(id.begin(),id.end());
ll now=idx.size();
for(int i=0;i+1<id.size();i++){
ans*=modPow(now,id[i+1]-id[i]-1,mod);
ans%=mod;
now--;
}
ans*=c;
ans%=mod;
return int(ans);
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:19:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
19 | if(s.size()!=n) return 0;
| ~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:67:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | if(s.size()!=n) ok=false;
| ~~~~~~~~^~~
gondola.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0;i+1<id.size();i++){
| ~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
10 ms |
2132 KB |
Output is correct |
7 |
Correct |
23 ms |
3628 KB |
Output is correct |
8 |
Correct |
19 ms |
3992 KB |
Output is correct |
9 |
Correct |
6 ms |
1364 KB |
Output is correct |
10 |
Correct |
23 ms |
4496 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 |
10 ms |
2132 KB |
Output is correct |
7 |
Correct |
23 ms |
3580 KB |
Output is correct |
8 |
Correct |
18 ms |
3916 KB |
Output is correct |
9 |
Correct |
6 ms |
1364 KB |
Output is correct |
10 |
Correct |
25 ms |
4436 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
11 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
27 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
1 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
9 ms |
2808 KB |
Output is correct |
12 |
Correct |
9 ms |
2960 KB |
Output is correct |
13 |
Correct |
22 ms |
4180 KB |
Output is correct |
14 |
Correct |
8 ms |
2772 KB |
Output is correct |
15 |
Correct |
25 ms |
3796 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
7344 KB |
Output is correct |
10 |
Correct |
32 ms |
6024 KB |
Output is correct |
11 |
Correct |
12 ms |
2772 KB |
Output is correct |
12 |
Correct |
15 ms |
3176 KB |
Output is correct |
13 |
Correct |
4 ms |
980 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
45 ms |
7384 KB |
Output is correct |
10 |
Correct |
33 ms |
5964 KB |
Output is correct |
11 |
Correct |
13 ms |
2772 KB |
Output is correct |
12 |
Correct |
15 ms |
3180 KB |
Output is correct |
13 |
Correct |
3 ms |
980 KB |
Output is correct |
14 |
Correct |
56 ms |
9420 KB |
Output is correct |
15 |
Correct |
64 ms |
10804 KB |
Output is correct |
16 |
Correct |
10 ms |
2444 KB |
Output is correct |
17 |
Correct |
41 ms |
7500 KB |
Output is correct |
18 |
Correct |
22 ms |
4616 KB |
Output is correct |