#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)
#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)
int valid(int N, int *A) {
map<int, int> cnt;
FOR(i, 0, N-1)
if (++cnt[--A[i]] > 1)
return 0;
FOR(i, 0, N-1)
if (A[i] < N) {
FOR(j, 0, N-1)
if (A[(i+j)%N] < N && A[(i+j)%N] != (A[i]+j)%N)
return 0;
break;
}
return 1;
}
int replacement(int N, int *A, int *ans) {
int start = 0;
FOR(i, 0, N-1)
if (A[i]-- < N)
start = i;
vt<int> B(N);
FOR(i, 0, N-1)
B[(start+i)%N] = (A[start] + i) % N;
vt<int> ord(N);
iota(all(ord), 0);
sort(all(ord), [&](const int &a, const int &b) {
return A[a] < A[b];
});
vt<int> res;
FOR(ii, 0, N-1) {
int i = ord[ii];
if (A[i] < N)
continue;
res.push_back(B[i]);
B[i] = N - 1 + size(res);
for (; B[i] < A[i]; B[i]++)
res.push_back(B[i]);
}
FOR(i, 0, size(res)-1)
ans[i] = res[i] + 1;
return size(res);
}
constexpr int MOD = 1e9 + 9;
int binpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1, a = 1ll * a * a % MOD)
if (b & 1)
ret = 1ll * ret * a % MOD;
return ret;
}
int countReplacement(int N, int *A) {
if (!valid(N, A))
return 0;
sort(A, A+N);
int ans = 1;
FOR(i, 0, N-1)
if (A[i] >= N) {
#ifdef DEBUG
cout << "bruh: " << binpow(N - i, A[i] - (i ? max(N-1, A[i-1])+1 : N)) << ' ' << A[i] << ' ' << A[i-1] << '\n';
#endif
ans = 1ll * ans * binpow(N - i, A[i] - (i ? max(N-1, A[i-1])+1 : N)) % MOD;
}
return 1ll * ans * (A[0] >= N ? N : 1) % MOD;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2140 KB |
Output is correct |
7 |
Correct |
7 ms |
604 KB |
Output is correct |
8 |
Correct |
15 ms |
3928 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
18 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2140 KB |
Output is correct |
7 |
Correct |
7 ms |
604 KB |
Output is correct |
8 |
Correct |
16 ms |
3932 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
18 ms |
4652 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
11 ms |
2140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
29 ms |
5372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
544 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
1396 KB |
Output is correct |
12 |
Correct |
11 ms |
1368 KB |
Output is correct |
13 |
Correct |
12 ms |
1492 KB |
Output is correct |
14 |
Correct |
9 ms |
1628 KB |
Output is correct |
15 |
Correct |
17 ms |
2608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
4056 KB |
Output is correct |
10 |
Correct |
23 ms |
3420 KB |
Output is correct |
11 |
Correct |
8 ms |
1392 KB |
Output is correct |
12 |
Correct |
10 ms |
1628 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
4156 KB |
Output is correct |
10 |
Correct |
23 ms |
3420 KB |
Output is correct |
11 |
Correct |
8 ms |
1428 KB |
Output is correct |
12 |
Correct |
10 ms |
1628 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
35 ms |
4484 KB |
Output is correct |
15 |
Correct |
43 ms |
5004 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
26 ms |
3676 KB |
Output is correct |
18 |
Correct |
14 ms |
2140 KB |
Output is correct |