#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 9;
const int INF = (int) 1e9;
int valid(int n, int inputSeq[]) {
int id = 0, pos;
map <int, bool> mp;
for(int i = 0; i < n; i++) {
if(mp[inputSeq[i]] == 1) {
return 0;
}
mp[inputSeq[i]] = 1;
if(inputSeq[i] <= n) {
id = inputSeq[i];
pos = i;
}
}
if(id != 0) {
int cur = id;
int i = pos;
do {
if(inputSeq[i] <= n && inputSeq[i] != cur) {
return 0;
}
cur++;
if(cur == n + 1) {
cur = 1;
}
i = (i + 1) % n;
}while(i != pos);
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vector <int> positions;
for(int i = 0; i < n; i++) {
if(gondolaSeq[i] > n) {
positions.push_back(i);
}
}
sort(positions.begin(), positions.end(), [&](const int &a, const int &b) {
return gondolaSeq[a] < gondolaSeq[b];
});
map <int, int> mp;
int id = 0, pos, mx = 0;
for(int i = 0; i < n; i++) {
mp[gondolaSeq[i]] = i + 1;
mx = max(mx, gondolaSeq[i]);
if(gondolaSeq[i] <= n) {
id = gondolaSeq[i];
pos = i;
}
}
vector <int> ord(n);
iota(ord.begin(), ord.end(), 1);
if(id != 0) {
int i = pos;
do {
ord[i] = id;
id++;
if(id == n + 1) {
id = 1;
}
i = (i + 1) % n;
}while(i != pos);
}
pos = 0;
int sz = 0;
for(int i = n + 1; i <= mx; i++) {
replacementSeq[sz++] = ord[positions[pos]];
ord[positions[pos]] = i;
if(mp[i] > 0) {
pos++;
}
}
return sz;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq)) {
return 0;
}
map <int, int> mp;
int cnt = 0, mx = 0;
for(int i = 0; i < n; i++) {
mp[inputSeq[i]] = i + 1;
mx = max(mx, inputSeq[i]);
if(inputSeq[i] > n) {
cnt++;
}
}
int ans = 1;
for(int i = n + 1; i <= mx; i++) {
if(mp[i] > 0) {
cnt--;
}
else {
ans = (1LL * ans * cnt) % MOD;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
17 ms |
2432 KB |
Output is correct |
7 |
Correct |
12 ms |
1152 KB |
Output is correct |
8 |
Correct |
32 ms |
4344 KB |
Output is correct |
9 |
Correct |
11 ms |
1664 KB |
Output is correct |
10 |
Correct |
42 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
2432 KB |
Output is correct |
7 |
Correct |
17 ms |
1252 KB |
Output is correct |
8 |
Correct |
35 ms |
4472 KB |
Output is correct |
9 |
Correct |
13 ms |
1536 KB |
Output is correct |
10 |
Correct |
44 ms |
5112 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
27 ms |
2432 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
74 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
404 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
636 KB |
Output is correct |
11 |
Correct |
34 ms |
5244 KB |
Output is correct |
12 |
Correct |
42 ms |
5880 KB |
Output is correct |
13 |
Correct |
51 ms |
4984 KB |
Output is correct |
14 |
Correct |
38 ms |
5112 KB |
Output is correct |
15 |
Correct |
71 ms |
10280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
137 ms |
7188 KB |
Output is correct |
10 |
Correct |
93 ms |
5280 KB |
Output is correct |
11 |
Correct |
65 ms |
10052 KB |
Output is correct |
12 |
Correct |
52 ms |
5240 KB |
Output is correct |
13 |
Incorrect |
68 ms |
10488 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
412 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
122 ms |
7160 KB |
Output is correct |
10 |
Correct |
75 ms |
5240 KB |
Output is correct |
11 |
Correct |
66 ms |
10104 KB |
Output is correct |
12 |
Correct |
53 ms |
5240 KB |
Output is correct |
13 |
Incorrect |
68 ms |
10488 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |