#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double
const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 9;
int valid(int n, int inputSeq[]) {
vector<int> a(n);
set<int> lol;
for (int i = 0; i < n; i++) {
a[i] = inputSeq[i];
lol.insert(a[i]);
}
if ((int)lol.size() != n) return 0;
int ind = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) ind = i;
}
if (ind == -1) return 1;
int now = a[ind];
for (int i = 0; i < n; i++) {
if (a[ind] <= n && a[ind] != now) return 0;
ind++;
if (ind >= n) ind -= n;
now++;
if (now > n) now = 1;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vector<int> a(n);
for (int i = 0; i < n; i++) a[i] = gondolaSeq[i];
vector<int> lol;
int ind = -1;
for (int i = 0; i < n; i++) {
if (a[i] > n) lol.pb(a[i]);
else ind = i;
}
vector<int> ans;
sort(all(lol));
map<int, int> ma;
if (ind == -1) {
for (int i = 1; i <= n; i++) {
ma[a[i - 1]] = i;
}
} else {
int now = a[ind];
for (int i = 0; i < n; i++) {
if (a[ind] > n) {
ma[a[ind]] = now;
}
now++;
if (now > n) now = 1;
ind++;
if (ind >= n) ind -= n;
}
}
int last = n;
for (auto &c : lol) {
while (last + 1 <= c) {
assert(ma[c] > 0);
ans.pb(ma[c]);
ma[c] = last + 1;
last++;
}
}
int len = ans.size();
for (int i = 0; i < len; i++) replacementSeq[i] = ans[i];
/*
cout << len << endl;
for (auto &c : ans) cout << c << " ";
*/
return len;
}
ll my_pow(ll n, ll m) {
if (m == 0) return 1;
ll now = my_pow(n, m / 2);
if (m % 2 == 0) return (now * now) % mod;
return (((now * now) % mod) * n) % mod;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
vector<int> a(n);
bool f = false, is_fixed = false;
vector<int> lol;
ll cnt = n;
for (int i = 0; i < n; i++) {
a[i] = inputSeq[i];
if (a[i] > n) {
f = true;
lol.pb(a[i]);
}
if (a[i] <= n) {
is_fixed = true;
cnt--;
}
}
if (!f) return 1;
sort(all(lol));
ll last = n;
ll ans = 1;
for (int i = 0; i < (int)lol.size(); i++) {
ans *= my_pow(cnt, lol[i] - last - 1);
ans %= mod;
last = lol[i];
cnt--;
}
if (!is_fixed) {
ans *= n;
ans %= mod;
}
return ans;
}
/*
int main() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
replacement(n, a, b);
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
436 KB |
Output is correct |
6 |
Correct |
16 ms |
2560 KB |
Output is correct |
7 |
Correct |
36 ms |
3968 KB |
Output is correct |
8 |
Correct |
27 ms |
4224 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
33 ms |
4864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
17 ms |
2432 KB |
Output is correct |
7 |
Correct |
37 ms |
4088 KB |
Output is correct |
8 |
Correct |
28 ms |
4224 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
34 ms |
4864 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
20 ms |
2304 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
52 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
308 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
15 ms |
1408 KB |
Output is correct |
12 |
Correct |
18 ms |
1536 KB |
Output is correct |
13 |
Correct |
42 ms |
3060 KB |
Output is correct |
14 |
Correct |
16 ms |
1408 KB |
Output is correct |
15 |
Correct |
43 ms |
3284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
45 ms |
4340 KB |
Output is correct |
10 |
Correct |
36 ms |
3704 KB |
Output is correct |
11 |
Correct |
16 ms |
1536 KB |
Output is correct |
12 |
Correct |
19 ms |
1792 KB |
Output is correct |
13 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
44 ms |
4344 KB |
Output is correct |
10 |
Correct |
42 ms |
3704 KB |
Output is correct |
11 |
Correct |
17 ms |
1536 KB |
Output is correct |
12 |
Correct |
20 ms |
1792 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
64 ms |
4984 KB |
Output is correct |
15 |
Correct |
64 ms |
5624 KB |
Output is correct |
16 |
Correct |
14 ms |
1280 KB |
Output is correct |
17 |
Correct |
42 ms |
3832 KB |
Output is correct |
18 |
Correct |
25 ms |
2304 KB |
Output is correct |