#include "gondola.h"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 100010;
const int MOD = 1000000009;
int32_t valid(int32_t n, int32_t inputSeq[]) {
vector<int> owo;
vector<int> al;
int p = -1;
For(i, 0, n - 1) {
int x = inputSeq[i];
if(x <= n) p = i;
al.eb(x);
}
sort(all(al));
if(unique(all(al)) != al.end()) return 0;
if(p == -1) return 1;
For(i, 0, n - 1) {
int j = (p + i) % n;
int vj = (inputSeq[p] - 1 + i) % n + 1;
if(inputSeq[j] <= n && inputSeq[j] != vj) return 0;
}
return 1;
}
//----------------------
int32_t replacement(int32_t n, int32_t a[], int32_t res[]) {
assert(valid(n, a));
vector<pii> v; // {index, value}
vector<int> b(n);
int p = -1;
For(i, 0, n - 1) {
if(a[i] > n) v.eb(i, a[i]);
else p = i;
}
sort(all(v), [&](pii p1, pii p2) {
return p1.S < p2.S;
});
if(p < 0) {
For(i, 0, n - 1) b[i] = i + 1;
} else {
For(i, 0, n - 1) b[(p + i) % n] = (a[p] + i - 1) % n + 1;
}
int last = n;
int ptr = 0;
for(auto &it:v) {
int t = b[it.F];
For(i, last + 1, it.S) {
res[ptr] = (int32_t)t; ptr++;
t = i;
}
last = it.S;
}
return (int32_t)ptr;
}
//----------------------
int fpow(int b, int p) {
int res = 1;
while(p) {
if(p & 1) res = res * b % MOD;
b = b * b % MOD; p /= 2;
}
return res;
}
int32_t countReplacement(int32_t n, int32_t a[]) {
if(!valid(n, a)) return 0;
vector<int> v;
int oao = n;
For(i, 0, n - 1) {
if(a[i] > n) v.eb(a[i]);
else oao = 1;
}
sort(all(v));
if(!sz(v)) return 1;
int res = 1;
int last = n;
For(i, 0, sz(v) - 1) {
res = res * fpow(sz(v) - i, v[i] - last - 1) % MOD;
last = v[i];
}
res = res * oao % MOD;
return (int32_t)res;
}
# |
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 |
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 |
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 |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
13 ms |
1776 KB |
Output is correct |
8 |
Correct |
9 ms |
1740 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
14 ms |
1788 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
14 ms |
1740 KB |
Output is correct |
8 |
Correct |
10 ms |
1740 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
13 ms |
1740 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
976 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
13 ms |
1740 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 |
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 |
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 |
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 |
# |
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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
11 ms |
1740 KB |
Output is correct |
12 |
Correct |
12 ms |
1740 KB |
Output is correct |
13 |
Correct |
20 ms |
1900 KB |
Output is correct |
14 |
Correct |
10 ms |
1740 KB |
Output is correct |
15 |
Correct |
18 ms |
2296 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 |
# |
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 |
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 |
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 |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
17 ms |
1712 KB |
Output is correct |
10 |
Correct |
15 ms |
1388 KB |
Output is correct |
11 |
Correct |
5 ms |
832 KB |
Output is correct |
12 |
Correct |
7 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
340 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 |
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 |
18 ms |
1740 KB |
Output is correct |
10 |
Correct |
13 ms |
1388 KB |
Output is correct |
11 |
Correct |
5 ms |
800 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
22 ms |
2240 KB |
Output is correct |
15 |
Correct |
25 ms |
3316 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
17 ms |
2124 KB |
Output is correct |
18 |
Correct |
11 ms |
1592 KB |
Output is correct |