#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define pii pair<int,int>
#define ll long long
ll ans=1;
int valid(int n, int inputSeq[]){
set<int> s(inputSeq,inputSeq+n);
if ((int)s.size()<n)return 0;
pii mn={n+1,-1};
for (int i = 0; i<n; i++){
if (inputSeq[i]<mn.first)mn={inputSeq[i],i};
}
int cur=mn.first;
if (cur==n+1)ans*=n;
for (int i = mn.second+1; ++cur<=n; i++){
if (inputSeq[i%n]<=n && inputSeq[i%n]!=cur)return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int st=0;
for (int i = 0; i<n; i++){
if (gondolaSeq[i]<=n){
st=(i-gondolaSeq[i]+1+n)%n;
break;
}
}
vector<int> kol(n);
for (int i = st; i<n+st; i++)kol[i-st]=gondolaSeq[i%n];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int l=0,bro=n;
for (int i = 0; i<n; i++){
if (kol[i]>n)pq.push({kol[i],i+1});
}
while(pq.size()){
pii now=pq.top();
pq.pop();
replacementSeq[l++]=now.second;
bro++;
while(bro<now.first)replacementSeq[l++]=bro++;
}
return l;
}
ll mod=1e9+9;
ll fast_pow(ll a, ll b){
if (b==1)return a;
if (b==0)return 1;
ll cur=fast_pow(a,b/2);
cur=(cur*cur)%mod;
if (b&1)cur=(cur*a)%mod;
return cur;
}
int countReplacement(int n, int inputSeq[]){
if (!valid(n,inputSeq))return 0;
priority_queue<ll,vector<ll>,greater<ll>> pq;
for (int i = 0; i<n; i++){
if (inputSeq[i]>n)pq.push(inputSeq[i]);
}
ll prv=n;
for (int i = pq.size(); i; i--){
ans=(ans*fast_pow(i,pq.top()-prv-1))%mod;
prv=pq.top();
pq.pop();
}
return (int)ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
2396 KB |
Output is correct |
7 |
Correct |
21 ms |
4180 KB |
Output is correct |
8 |
Correct |
21 ms |
4432 KB |
Output is correct |
9 |
Correct |
4 ms |
1628 KB |
Output is correct |
10 |
Correct |
13 ms |
5088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2492 KB |
Output is correct |
7 |
Correct |
20 ms |
4180 KB |
Output is correct |
8 |
Correct |
21 ms |
4304 KB |
Output is correct |
9 |
Correct |
4 ms |
1636 KB |
Output is correct |
10 |
Correct |
19 ms |
5160 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
2356 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
32 ms |
5296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1372 KB |
Output is correct |
12 |
Correct |
15 ms |
1592 KB |
Output is correct |
13 |
Correct |
12 ms |
1496 KB |
Output is correct |
14 |
Correct |
7 ms |
1372 KB |
Output is correct |
15 |
Correct |
25 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
28 ms |
4576 KB |
Output is correct |
10 |
Correct |
22 ms |
3932 KB |
Output is correct |
11 |
Correct |
10 ms |
1628 KB |
Output is correct |
12 |
Correct |
11 ms |
1884 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
34 ms |
4556 KB |
Output is correct |
10 |
Correct |
23 ms |
3680 KB |
Output is correct |
11 |
Correct |
12 ms |
1596 KB |
Output is correct |
12 |
Correct |
11 ms |
1884 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
40 ms |
5468 KB |
Output is correct |
15 |
Correct |
43 ms |
6152 KB |
Output is correct |
16 |
Correct |
10 ms |
1368 KB |
Output is correct |
17 |
Correct |
31 ms |
4076 KB |
Output is correct |
18 |
Correct |
17 ms |
2888 KB |
Output is correct |