#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int maxn = 250005;
const int mod=1e9+9;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=1LL*res*a%mod;
a=1LL*a*a%mod;n>>=1;
}
return res;
}
int cnt[maxn];
int valid(int n, int p[])
{
int del=-1;
for(int i=0;i<n;i++){
if(cnt[p[i]]) return 0;
cnt[p[i]]++;
if(p[i]<=n){
int cur=(i-p[i]+n)%n;
if(del==-1) del=cur;
else if(del!=cur) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int p[], int res[])
{
int del=0,sz=0;
for(int i=0;i<n;i++) if(p[i]<=n) del=(i-p[i]+1+n)%n;
deque<int> dq(n);
for(int i=0;i<n;i++) dq[i]=p[i];
while(del){
del--;
dq.push_back(dq.front());
dq.pop_front();
}
vector<pii> pp;
for(int i=0;i<n;i++) if(dq[i]>n) pp.push_back({dq[i],i});
sort(pp.begin(),pp.end());
int pre=n;
for(auto &[x,id]:pp){
res[sz++]=id+1;pre++;
while(pre<x) res[sz++]=pre++;
}
return sz;
}
//----------------------
int countReplacement(int n, int p[])
{
if(!valid(n,p)) return 0;
vector<int> pp;
int res=n,cnt=n;
for(int i=0;i<n;i++){
if(p[i]<=n) res=1,cnt--;
else pp.push_back(p[i]);
}
int pre=n;
sort(pp.begin(),pp.end());
for(int x:pp){
res=1LL*res*power(cnt,x-pre-1)%mod;
pre=x;cnt--;
}
return res;
}
# |
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 |
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 |
# |
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 |
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 |
3 ms |
820 KB |
Output is correct |
7 |
Correct |
6 ms |
1108 KB |
Output is correct |
8 |
Correct |
6 ms |
1220 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
6 ms |
1332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 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 |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
7 ms |
1100 KB |
Output is correct |
8 |
Correct |
5 ms |
1236 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
1364 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
3 ms |
980 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
6 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 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 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
264 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
6 ms |
1340 KB |
Output is correct |
12 |
Correct |
7 ms |
1492 KB |
Output is correct |
13 |
Correct |
11 ms |
1644 KB |
Output is correct |
14 |
Correct |
6 ms |
1364 KB |
Output is correct |
15 |
Correct |
16 ms |
2360 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 |
# |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
304 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 |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
10 ms |
2156 KB |
Output is correct |
10 |
Correct |
8 ms |
1856 KB |
Output is correct |
11 |
Correct |
4 ms |
1428 KB |
Output is correct |
12 |
Correct |
5 ms |
1328 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
11 ms |
2156 KB |
Output is correct |
10 |
Correct |
8 ms |
1776 KB |
Output is correct |
11 |
Correct |
4 ms |
1364 KB |
Output is correct |
12 |
Correct |
4 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Runtime error |
8 ms |
1908 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |