#include "gondola.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))
#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;
int valid(int n,int a[]){
int bgn=-1; bool ok = 1;
set<int> s;
rep(i,0,n){
if(a[i]<=n){
if(bgn==-1) bgn = i;
int k = i-bgn;
ok &= (a[bgn]+k - a[i])%n==0;
}
ok &= 0<a[i];
ok &= !s.count(a[i]);
s.insert(a[i]);
}
return ok;
}
//----------------------
int replacement(int n,int a[],int ans[]){
map<int,int> mp;
int bgn = 0;
rep(i,0,n) if(a[i] <= n){
bgn = i; break;
}
// dbg(bgn);
rep(i,0,n) if(a[i] > n){
int ori = (i-bgn + a[bgn] -1 + n)%n+1;
// dbg(ori);
mp[a[i]] = ori;
}
int l=n+1, sz=0;
for(auto[r,i] : mp){
ans[sz++] = i;
while(l < r){
ans[sz++] = l++;
}
l = r+1;
}
return sz;
}
//----------------------
const Int MOD = 1000000009;
Int bpow(Int a,Int b){
Int ret = 1;
while(b){
if(b&1) ret = ret*a%MOD;
a = a*a%MOD; b /= 2;
}
return ret;
}
int countReplacement(int n,int a[]){
if(!valid(n,a)) return 0;
Int ans = 1;
bool smol = 0;
set<int> s;
rep(i,0,n){
if(a[i] > n){
s.insert(a[i]);
}
smol |= a[i]<=n;
}
if(!smol){
ans = n;
}
int l = n+1, chc = s.size();
for(int r : s){
ans *= bpow(chc, r-l)%MOD;
ans %= MOD;
chc--;
l = r+1;
}
assert(0<ans && ans<MOD);
if((int)s.size() <= 1) assert(ans==1);
ans = (ans%MOD+MOD)%MOD;
return (int)ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
13 ms |
2136 KB |
Output is correct |
7 |
Correct |
31 ms |
3624 KB |
Output is correct |
8 |
Correct |
22 ms |
3916 KB |
Output is correct |
9 |
Correct |
7 ms |
1364 KB |
Output is correct |
10 |
Correct |
36 ms |
4512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
2132 KB |
Output is correct |
7 |
Correct |
30 ms |
3564 KB |
Output is correct |
8 |
Correct |
22 ms |
3900 KB |
Output is correct |
9 |
Correct |
7 ms |
1364 KB |
Output is correct |
10 |
Correct |
30 ms |
4576 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
13 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
36 ms |
4672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
6 |
Correct |
1 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 |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
12 ms |
736 KB |
Output is correct |
13 |
Correct |
19 ms |
2516 KB |
Output is correct |
14 |
Correct |
7 ms |
596 KB |
Output is correct |
15 |
Correct |
22 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
3916 KB |
Output is correct |
10 |
Correct |
33 ms |
3372 KB |
Output is correct |
11 |
Correct |
13 ms |
1364 KB |
Output is correct |
12 |
Correct |
16 ms |
1700 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
3924 KB |
Output is correct |
10 |
Correct |
34 ms |
3408 KB |
Output is correct |
11 |
Correct |
12 ms |
1364 KB |
Output is correct |
12 |
Correct |
16 ms |
1620 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
60 ms |
5372 KB |
Output is correct |
15 |
Correct |
70 ms |
6024 KB |
Output is correct |
16 |
Correct |
10 ms |
1344 KB |
Output is correct |
17 |
Correct |
42 ms |
4040 KB |
Output is correct |
18 |
Correct |
23 ms |
2376 KB |
Output is correct |