#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#ifdef B01
#include "../deb.h"
#else
#define deb(...)
#endif
const int md = 1000000009;
inline int mul(int a, int b) {
a %= md;
b %= md;
return (int) ((long long) a * b % md);
}
int valid(int n, int p[]) {
{
vector<int> d(n);
for (int i = 0; i < n; i++) {
d[i] = p[i];
}
sort(d.begin(), d.end());
d.resize(unique(d.begin(), d.end()) - d.begin());
if ((int) d.size() != n) {
return 0;
}
}
vector<int> a(n);
int s = (int) (min_element(p, p + n) - p);
if (p[s] > n) {
return 1;
}
for (int i = 0; i < n; i++) {
a[(i + p[s] - 1) % n] = p[(s + i) % n];
}
vector<int> b;
for (int i = 0; i < n; i++) {
if (a[i] <= n && a[i] != i + 1) {
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int p[], int res[]) {
int mxi = (int) (max_element(p, p + n) - p);
int m = p[mxi] - n;
vector<int> a(n);
int s = (int) (min_element(p, p + n) - p);
if (p[s] <= n) {
for (int i = 0; i < n; i++) {
a[(i + p[s] - 1) % n] = p[(s + i) % n];
}
} else {
for (int i = 0; i < n; i++) {
a[i] = p[i];
}
}
mxi = (int) (max_element(a.begin(), a.end()) - a.begin());
vector<int> at(a[mxi] + 1, -1);
for (int i = 0; i < n; i++) {
if (a[i] > n) {
at[a[i]] = i + 1;
}
}
at[a[mxi]] = -1;
mxi++;
for (int i = 0; i < m; i++) {
int v = n + i + 1;
if (at[v] == -1) {
res[i] = mxi;
mxi = v;
} else {
res[i] = at[v];
}
}
return m;
}
//----------------------
int countReplacement(int n, int p[]) {
if (!valid(n, p)) {
return 0;
}
int m = *max_element(p, p + n) - n;
if (m == 0) {
return 1;
}
vector<int> a(n);
for (int i = 0; i < n; i++) {
a[i] = p[i];
}
sort(a.begin(), a.end());
int ans = 1;
for (int i = 0; i < m; i++) {
int v = n + i + 1;
auto it = lower_bound(a.begin(), a.end(), v);
if (*it == v) {
continue;
}
assert(it == upper_bound(a.begin(), a.end(), v));
ans = mul(ans % md, (int) (a.end() - it) % md);
}
return ans % md;
}
# |
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 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
596 KB |
Output is correct |
7 |
Correct |
11 ms |
980 KB |
Output is correct |
8 |
Correct |
8 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
908 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 |
5 ms |
596 KB |
Output is correct |
7 |
Correct |
11 ms |
980 KB |
Output is correct |
8 |
Correct |
8 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
976 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
5 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
12 ms |
960 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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
11 |
Correct |
7 ms |
1236 KB |
Output is correct |
12 |
Correct |
8 ms |
1252 KB |
Output is correct |
13 |
Correct |
9 ms |
1236 KB |
Output is correct |
14 |
Correct |
7 ms |
1204 KB |
Output is correct |
15 |
Correct |
14 ms |
2168 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 |
# |
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 |
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 |
# |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
280 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
21 ms |
892 KB |
Output is correct |
10 |
Correct |
16 ms |
800 KB |
Output is correct |
11 |
Correct |
11 ms |
484 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
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 |
21 ms |
892 KB |
Output is correct |
10 |
Correct |
17 ms |
796 KB |
Output is correct |
11 |
Correct |
11 ms |
468 KB |
Output is correct |
12 |
Correct |
11 ms |
520 KB |
Output is correct |
13 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |