#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;
for(int i = 0;i<n;++i){
if(s.find(inputSeq[i]) != s.end()){
return 0;
}
s.insert(inputSeq[i]);
}
int pos = -1;
for(int i = 0;i<n;++i){
if(inputSeq[i] <= n){
if(pos == -1){
pos = i;
}
else{
int ch = i+inputSeq[pos]-pos+n;
ch %= n;
if(ch == 0) ch = n;
if(inputSeq[i] != ch) 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;
shift %= n;
}
}
priority_queue<pair<int,int>> pq;
for(int i = 0;i<n;++i){
int realpos = (i-shift+n)%n;
if(gondolaSeq[realpos] > n){
pq.push({gondolaSeq[realpos],i+1});
}
}
int l = 0, cur = n+1; //length of the replacement sequence
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 pow(int a, int x){
ll res = 1, cur = a;
while(x != 0){
if(x & 1) res *= cur;
cur *= cur;
cur %= MOD;
res %= MOD;
x /= 2;
}
return res;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq)) return 0;
int num = 0;
int newseq[100005] = {};
for(int i = 0;i<n;++i){
if(inputSeq[i] > n){
newseq[num++] = inputSeq[i];
}
}
if(num == 0) return 1;
sort(newseq,newseq+num);
long long ans = 1; int cnt = num;
if(num == n) ans = num;
int last = n;
for(int i = 0;i<num;++i){
ans *= pow(cnt,newseq[i]-last-1);
ans %= MOD;
last = newseq[i];
cnt--;
}
return (int)ans;
}
# |
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 |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2364 KB |
Output is correct |
7 |
Correct |
7 ms |
1132 KB |
Output is correct |
8 |
Correct |
19 ms |
4308 KB |
Output is correct |
9 |
Correct |
6 ms |
1592 KB |
Output is correct |
10 |
Correct |
24 ms |
4952 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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2352 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
20 ms |
4284 KB |
Output is correct |
9 |
Correct |
6 ms |
1492 KB |
Output is correct |
10 |
Correct |
24 ms |
4992 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
12 ms |
2252 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
5120 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
224 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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
688 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 |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
740 KB |
Output is correct |
6 |
Correct |
1 ms |
692 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 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 |
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 |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
692 KB |
Output is correct |
9 |
Correct |
30 ms |
4820 KB |
Output is correct |
10 |
Correct |
24 ms |
4164 KB |
Output is correct |
11 |
Correct |
9 ms |
1876 KB |
Output is correct |
12 |
Correct |
11 ms |
2264 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 |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
696 KB |
Output is correct |
5 |
Correct |
1 ms |
692 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
32 ms |
4820 KB |
Output is correct |
10 |
Correct |
25 ms |
4092 KB |
Output is correct |
11 |
Correct |
9 ms |
1932 KB |
Output is correct |
12 |
Correct |
11 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
960 KB |
Output is correct |
14 |
Correct |
39 ms |
5708 KB |
Output is correct |
15 |
Correct |
54 ms |
6360 KB |
Output is correct |
16 |
Correct |
7 ms |
1724 KB |
Output is correct |
17 |
Correct |
27 ms |
4424 KB |
Output is correct |
18 |
Correct |
15 ms |
2796 KB |
Output is correct |