#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e5 + 1;
const int M = (int) 1e9 + 1;
const int md = (int) 1e9 + 9;
inline int binPow(int a, long long p){
int res = 1;
while (p){
if (p & 1) res = (long long) res * a % md;
a = (long long) a * a % md;
p >>= 1LL;
}
return res;
}
int n;
int mx;
int a[N];
int b[N];
bitset<M> vis;
bool Go (int id, int cur, int step) {
if (id < 0 || id >= n) {
return true;
}
if (cur == 0) cur = n;
if (cur == n + 1) cur = 1;
b[id] = cur;
if (a[id] <= n && a[id] != cur) {
return false;
}
return Go(id + step, cur + step, step);
};
int valid(int n_, int inputSeq[]) {
n = n_;
for (int i = 0; i < n; ++i) {
a[i] = inputSeq[i];
}
for (int i = 0; i < n; ++i) {
if (vis[a[i]] == true) {
return false;
}
mx = max(mx, a[i]);
vis[a[i]] = true;
}
bool ret = true;
for (int i = 0; i < n; ++i) {
if (inputSeq[i] <= n) {
ret &= Go(i, a[i], 1);
vis[inputSeq[i]] = 0;
ret &= Go(i, a[i], -1);
break;
}
}
return ret;
}
int replacement(int n_, int gondolaSeq[], int replacementSeq[]) {
n = n_;
for (int i = 0; i < n; ++i) {
a[i] = gondolaSeq[i];
}
bool f = false;
for (int i = 0; i < n; ++i) {
mx = max(mx, a[i]);
vis[a[i]] = true;
if (a[i] <= n) {
f = true;
}
}
int ans = 0;
if (!f) {
for (int i = 1; i <= mx; ++i) {
if (!vis[i]) {
replacementSeq[ans++] = i;
}
}
return ans;
}
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
Go(i, a[i], 1);
Go(i, a[i], -1);
break;
}
}
vector<pair<int, int>> ord;
for (int i = 0; i < n; ++i) {
if (a[i] > n) {
ord.push_back(make_pair(a[i], b[i]));
}
}
sort(ord.begin(), ord.end());
for (int p = 0, g = n + 1; p < (int) ord.size(); ++p) {
replacementSeq[ans++] = ord[p].second;
while (g < ord[p].first) {
replacementSeq[ans++] = g++;
}
g++;
}
return ans;
}
//----------------------
int countReplacement(int n_, int inputSeq[]) {
n = n_;
if (!valid(n, inputSeq)) {
return 0;
}
bool f = false;
for (int i = 0; i < n; ++i) {
a[i] = inputSeq[i];
if (inputSeq[i] <= n) {
f = true;
}
}
int ans = 1;
if (!f) {
ans = n;
}
vector<int> v;
for (int i = 0; i < n; ++i) {
v.push_back(a[i]);
}
if (!vis[n]) {
v.push_back(n);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < (int) v.size(); ++i) {
if (v[i] <= n) {
break;
}
int cnt = v[i] - v[i + 1] - 1;
int p = i + 1;
ans = (long long) ans * binPow(p, cnt) % md;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 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 |
4 ms |
824 KB |
Output is correct |
7 |
Correct |
8 ms |
1228 KB |
Output is correct |
8 |
Correct |
7 ms |
1204 KB |
Output is correct |
9 |
Correct |
3 ms |
636 KB |
Output is correct |
10 |
Correct |
8 ms |
1472 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
820 KB |
Output is correct |
7 |
Correct |
8 ms |
1236 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
10 ms |
1428 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
9 ms |
1224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
304 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 |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
312 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 |
304 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 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 |
212 KB |
Output is correct |
9 |
Correct |
15 ms |
2032 KB |
Output is correct |
10 |
Correct |
11 ms |
1464 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
5 ms |
932 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
312 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
15 ms |
2088 KB |
Output is correct |
10 |
Correct |
12 ms |
1476 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
5 ms |
1028 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
16 ms |
1872 KB |
Output is correct |
15 |
Correct |
18 ms |
2732 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
12 ms |
1876 KB |
Output is correct |
18 |
Correct |
8 ms |
1364 KB |
Output is correct |