#include "gondola.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int b[N], ind[N], mx, sz, cnt[N], mod = 1e9 + 9;
int valid(int n, int a[]) {
int pos = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
cnt[a[i]]++;
if (cnt[a[i]] > 1)
return 0;
}
if (pos == -1) {
return 1;
} else {
assert(a[pos] <= n);
int cn = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
if (a[i] > n) {
continue;
}
if (a[i] != cn) {
return 0;
}
}
}
return 1;
}
int replacement(int n, int a[], int ans[]) {
memset(ind, -1, sizeof(ind));
int pos = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
if (a[i] > a[mx]) {
mx = i;
}
ind[a[i]] = i;
}
if (pos == -1) {
for (int i = 0; i < n; i++) {
b[i] = i + 1;
}
}
else {
int cn = a[pos];
b[pos] = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
b[i] = cn;
}
}
for (int i = n + 1; i <= a[mx]; i++) {
if (ind[i] == -1) {
ans[sz++] = b[mx];
b[mx] = i;
}
else {
ans[sz++] = b[ind[i]];
b[ind[i]] = i;
}
}
return sz;
}
long long binpow (long long a, int b) {
if (b == 0)
return 1;
if (b & 1)
return a * 1ll * binpow(a, b - 1) % mod;
long long asd = binpow(a, b >> 1);
return asd * 1ll * asd % mod;
}
int countReplacement(int n, int a[]) {
int pos = -1;
long long res = 1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
}
if (pos == -1) {
res = n;
} else {
int cn = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
if (a[i] > n) {
continue;
}
if (a[i] != cn) {
return 0;
}
}
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] <= n) continue;
if (i > 0 && a[i] == a[i - 1])
return 0;
res *= binpow((n - i) * 1ll, ( (i == 0 || a[i - 1] <= n) ? a[i] - n - 1 : a[i] - a[i - 1] - 1) );
res %= mod;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
632 KB |
Output is correct |
7 |
Correct |
13 ms |
1016 KB |
Output is correct |
8 |
Correct |
12 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
13 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
632 KB |
Output is correct |
7 |
Correct |
14 ms |
1016 KB |
Output is correct |
8 |
Correct |
12 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
13 ms |
1016 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
8 ms |
1272 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
17 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4216 KB |
Output is correct |
2 |
Correct |
8 ms |
4216 KB |
Output is correct |
3 |
Correct |
5 ms |
4344 KB |
Output is correct |
4 |
Correct |
5 ms |
4216 KB |
Output is correct |
5 |
Correct |
5 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4216 KB |
Output is correct |
3 |
Correct |
5 ms |
4216 KB |
Output is correct |
4 |
Correct |
5 ms |
4216 KB |
Output is correct |
5 |
Correct |
5 ms |
4220 KB |
Output is correct |
6 |
Correct |
5 ms |
4216 KB |
Output is correct |
7 |
Correct |
5 ms |
4216 KB |
Output is correct |
8 |
Correct |
6 ms |
4344 KB |
Output is correct |
9 |
Correct |
6 ms |
4348 KB |
Output is correct |
10 |
Correct |
6 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4216 KB |
Output is correct |
3 |
Correct |
5 ms |
4264 KB |
Output is correct |
4 |
Correct |
5 ms |
4216 KB |
Output is correct |
5 |
Correct |
5 ms |
4216 KB |
Output is correct |
6 |
Correct |
5 ms |
4216 KB |
Output is correct |
7 |
Correct |
5 ms |
4216 KB |
Output is correct |
8 |
Correct |
6 ms |
4344 KB |
Output is correct |
9 |
Correct |
6 ms |
4216 KB |
Output is correct |
10 |
Correct |
7 ms |
4472 KB |
Output is correct |
11 |
Correct |
16 ms |
4856 KB |
Output is correct |
12 |
Correct |
17 ms |
4984 KB |
Output is correct |
13 |
Correct |
18 ms |
5240 KB |
Output is correct |
14 |
Correct |
16 ms |
4856 KB |
Output is correct |
15 |
Correct |
26 ms |
6136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
252 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
21 ms |
632 KB |
Output is correct |
10 |
Correct |
18 ms |
1016 KB |
Output is correct |
11 |
Correct |
8 ms |
504 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
21 ms |
632 KB |
Output is correct |
10 |
Correct |
17 ms |
888 KB |
Output is correct |
11 |
Correct |
8 ms |
632 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
372 KB |
Output is correct |
14 |
Correct |
27 ms |
1516 KB |
Output is correct |
15 |
Correct |
32 ms |
1656 KB |
Output is correct |
16 |
Correct |
7 ms |
504 KB |
Output is correct |
17 |
Correct |
21 ms |
1144 KB |
Output is correct |
18 |
Correct |
13 ms |
888 KB |
Output is correct |