#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
map<int, bool>mp;
for(int i=0; i<n; i++){
if(!mp[inputSeq[i]])
mp[inputSeq[i]]=true;
else return 0;
}
int fi=-1;
for(int i=0; i<n; i++){
if(inputSeq[i]<=n){
if(fi==-1) fi=i;
else{
int check=i+inputSeq[fi]-fi;
check%=n;
if(check==0) check=n;
if(check!=inputSeq[i]) return 0;
}
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int rotate=0;
for(int i=0; i<n; i++){
if(gondolaSeq[i]<=n) rotate=(n+gondolaSeq[i]-i-1)%n;
}
int now;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >pq;
for(int i=0; i<n; i++){
now=gondolaSeq[(n+i-rotate)%n];
if(now>n) pq.push({now, i+1});
}
int idx=0, cnt=n+1;
while(!pq.empty()){
int replacementGondola=pq.top().first;
int idxc=pq.top().second;
pq.pop();
replacementSeq[idx++]=idxc;
for(int i=cnt; i<replacementGondola; i++){
replacementSeq[idx++]=i;
}
cnt=replacementGondola+1;
}
return idx;
}
const long long mod=1000000009;
long long mdx(long long b, long long e){
long long res=1ll; b%=mod;
while(e>0){
if(e&1) res=(res*b)%mod;
e>>=1ll; b=(b*b)%mod;
}
return res;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
int more[100069]={};
int idxcnt=0;
for(int i=0; i<n; i++)
if(inputSeq[i]>n) more[idxcnt++]=inputSeq[i];
long long res=1ll;
if(idxcnt==n) res=(long long)n;
if(idxcnt==0) return 1;
int cnt=idxcnt, last=n;
sort(more, more+idxcnt);
for(int i=0; i<idxcnt; i++){
res=(res*mdx((long long)cnt, (long long)(more[i]-last-1)))%mod;
last=more[i]; cnt--;
}
return (int)res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
20 ms |
2424 KB |
Output is correct |
7 |
Correct |
14 ms |
1180 KB |
Output is correct |
8 |
Correct |
35 ms |
4344 KB |
Output is correct |
9 |
Correct |
12 ms |
1656 KB |
Output is correct |
10 |
Correct |
47 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
20 ms |
2424 KB |
Output is correct |
7 |
Correct |
14 ms |
1272 KB |
Output is correct |
8 |
Correct |
35 ms |
4344 KB |
Output is correct |
9 |
Correct |
12 ms |
1568 KB |
Output is correct |
10 |
Correct |
47 ms |
5112 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
24 ms |
2424 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
59 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
12 ms |
1144 KB |
Output is correct |
12 |
Correct |
13 ms |
1272 KB |
Output is correct |
13 |
Correct |
20 ms |
1456 KB |
Output is correct |
14 |
Correct |
12 ms |
1016 KB |
Output is correct |
15 |
Correct |
24 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
764 KB |
Output is correct |
8 |
Correct |
2 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
888 KB |
Output is correct |
9 |
Correct |
56 ms |
4984 KB |
Output is correct |
10 |
Correct |
45 ms |
4188 KB |
Output is correct |
11 |
Correct |
18 ms |
2040 KB |
Output is correct |
12 |
Correct |
22 ms |
2296 KB |
Output is correct |
13 |
Correct |
6 ms |
1148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
892 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
56 ms |
4984 KB |
Output is correct |
10 |
Correct |
45 ms |
4220 KB |
Output is correct |
11 |
Correct |
17 ms |
2040 KB |
Output is correct |
12 |
Correct |
21 ms |
2296 KB |
Output is correct |
13 |
Correct |
6 ms |
1016 KB |
Output is correct |
14 |
Correct |
72 ms |
5752 KB |
Output is correct |
15 |
Correct |
80 ms |
6392 KB |
Output is correct |
16 |
Correct |
14 ms |
1788 KB |
Output is correct |
17 |
Correct |
53 ms |
4600 KB |
Output is correct |
18 |
Correct |
29 ms |
2936 KB |
Output is correct |