#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
const int MOD = 1000000009;
ll expo(ll base, ll pwr) {
ll res = 1;
base %= MOD;
while (pwr) {
if (pwr % 2 == 1) res = (res * base) % MOD;
base = (base * base) % MOD;
pwr /= 2;
}
return res;
}
vector<int> ans;
bool solve(int n, int arr[]) {
ans.resize(n);
set<int> s;
int pos = -1;
for (int i = 0; i < n; i++) {
if (s.count(arr[i])) return 0;
s.insert(arr[i]);
if (arr[i] <= n) pos = i;
}
int val;
if (pos == -1) {
val = 1;
pos = 0;
}
else val = arr[pos];
ans[pos] = val;
for (int i = 0; i < n - 1; i++) {
pos = (pos + 1) % n;
val = val % n + 1;
ans[pos] = val;
if (arr[pos] < val) return 0;
}
return 1;
}
int valid(int n, int inputSeq[]) {
return solve(n, inputSeq);
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
solve(n, gondolaSeq);
int mx = 0;
for (int i = 0; i < n; i++) mx = max(mx, gondolaSeq[i]);
int pos[mx + 10];
memset(pos, -1, sizeof(pos));
set<int> notCorrect;
for (int i = 0; i < n; i++) {
pos[gondolaSeq[i]] = i;
if (gondolaSeq[i] > n) notCorrect.insert(i);
}
int cnt = 0;
for (int i = n + 1; i <= mx; i++) {
if (pos[i] == -1) {
replacementSeq[cnt] = ans[*notCorrect.begin()];
ans[*notCorrect.begin()] = i;
}
else {
replacementSeq[cnt] = ans[pos[i]];
ans[pos[i]] = i;
notCorrect.erase(pos[i]);
}
cnt++;
}
return cnt;
}
int countReplacement(int n, int inputSeq[]) {
bool res = solve(n, inputSeq);
if (res == 0) return 0;
set<ll> notCorrect;
vector<ll> v;
for (int i = 0; i < n; i++) {
if (inputSeq[i] > n) {
v.push_back(inputSeq[i]);
notCorrect.insert(i);
}
}
ll sz = notCorrect.size();
v.push_back(n);
sort(all(v));
ll cnt = 1;
for (int i = 1; i < v.size(); i++) {
ll time = v[i] - v[i - 1] - 1;
cnt *= expo(sz, time);
cnt %= MOD;
sz--;
}
return cnt;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:95:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
10 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
1116 KB |
Output is correct |
8 |
Correct |
19 ms |
4324 KB |
Output is correct |
9 |
Correct |
6 ms |
1628 KB |
Output is correct |
10 |
Correct |
23 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
1112 KB |
Output is correct |
8 |
Correct |
19 ms |
4216 KB |
Output is correct |
9 |
Correct |
6 ms |
1948 KB |
Output is correct |
10 |
Correct |
26 ms |
4912 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
12 ms |
2140 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
31 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
20 ms |
4956 KB |
Output is correct |
12 |
Correct |
23 ms |
5976 KB |
Output is correct |
13 |
Correct |
25 ms |
3416 KB |
Output is correct |
14 |
Correct |
24 ms |
4952 KB |
Output is correct |
15 |
Correct |
20 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
37 ms |
4300 KB |
Output is correct |
10 |
Correct |
28 ms |
3564 KB |
Output is correct |
11 |
Correct |
11 ms |
1880 KB |
Output is correct |
12 |
Correct |
13 ms |
2140 KB |
Output is correct |
13 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
46 ms |
4436 KB |
Output is correct |
10 |
Correct |
30 ms |
3612 KB |
Output is correct |
11 |
Correct |
10 ms |
1884 KB |
Output is correct |
12 |
Correct |
13 ms |
2108 KB |
Output is correct |
13 |
Incorrect |
3 ms |
1112 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |