#include "gondola.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+9;
int valid(int n, int inputSeq[]){
set<int> s;
int pos = -1;
for(int i = 0;i<n;++i){
if(s.find(inputSeq[i]) != s.end()) return 0;
if(inputSeq[i] <= n && pos == -1){
pos = i;
}
s.insert(inputSeq[i]);
}
if(pos == -1) return 1;
for(int i = 0;i<n;++i){
if(inputSeq[i] <= n && i != pos){
int d = (inputSeq[pos]+i-pos+n)%n;
if(d == 0) d = n;
if(d != inputSeq[i]) return 0;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int shift = -1;
for(int i = 0;i<n;++i){
if(gondolaSeq[i] <= n){
shift = (gondolaSeq[i]-i-1+n)%n;
}
}
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for(int i = 0;i<n;++i){
int d = (i-shift+n)%n;
if(gondolaSeq[d] > n){
pq.push({gondolaSeq[d],i+1});
}
}
int l = 0, cur = n+1;
while(!pq.empty()){
pair<int,int> p = pq.top(); pq.pop();
replacementSeq[l++] = p.second;
for(int i = cur;i<p.first;++i) replacementSeq[l++] = i;
cur = p.first+1;
}
return l;
}
ll binpow(int x, int k){
ll ans = 1, p = x;
while(k != 0){
if(k & 1) ans *= p;
p *= p;
p %= MOD;
ans %= MOD;
k /= 2;
}
return ans;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq)) return 0;
int newseq[100005] = {};
int cnt = 0;
for(int i = 0;i<n;++i){
if(inputSeq[i] > n){
newseq[cnt++] = inputSeq[i];
}
}
sort(newseq,newseq+cnt);
int last = n, cur = cnt; ll ans = 1;
if(cnt == n) ans = n;
for(int i = 0;i<cnt;++i){
ans *= binpow(cur,newseq[i]-last-1);
ans %= MOD;
last = newseq[i];
cur--;
}
return (int)ans;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 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 |
10 ms |
2388 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
19 ms |
4264 KB |
Output is correct |
9 |
Correct |
6 ms |
1492 KB |
Output is correct |
10 |
Correct |
26 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
14 ms |
2460 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
20 ms |
4288 KB |
Output is correct |
9 |
Correct |
6 ms |
1468 KB |
Output is correct |
10 |
Correct |
34 ms |
4972 KB |
Output is correct |
11 |
Correct |
0 ms |
304 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
12 ms |
2288 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
5092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
332 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 |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
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 |
304 KB |
Output is correct |
11 |
Correct |
11 ms |
980 KB |
Output is correct |
12 |
Correct |
8 ms |
1132 KB |
Output is correct |
13 |
Correct |
14 ms |
1444 KB |
Output is correct |
14 |
Correct |
8 ms |
1016 KB |
Output is correct |
15 |
Correct |
16 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
692 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
688 KB |
Output is correct |
4 |
Correct |
1 ms |
688 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
688 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
33 ms |
4788 KB |
Output is correct |
10 |
Correct |
28 ms |
4156 KB |
Output is correct |
11 |
Correct |
11 ms |
1864 KB |
Output is correct |
12 |
Correct |
13 ms |
2268 KB |
Output is correct |
13 |
Correct |
3 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
692 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
692 KB |
Output is correct |
7 |
Correct |
1 ms |
692 KB |
Output is correct |
8 |
Correct |
1 ms |
696 KB |
Output is correct |
9 |
Correct |
32 ms |
4776 KB |
Output is correct |
10 |
Correct |
26 ms |
4088 KB |
Output is correct |
11 |
Correct |
9 ms |
1936 KB |
Output is correct |
12 |
Correct |
11 ms |
2132 KB |
Output is correct |
13 |
Correct |
3 ms |
956 KB |
Output is correct |
14 |
Correct |
50 ms |
5676 KB |
Output is correct |
15 |
Correct |
53 ms |
6424 KB |
Output is correct |
16 |
Correct |
7 ms |
1652 KB |
Output is correct |
17 |
Correct |
27 ms |
4508 KB |
Output is correct |
18 |
Correct |
14 ms |
2772 KB |
Output is correct |