#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 = 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];
for (int i = 0; i <= mx + 5; i++) pos[i] = -1;
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<int> notCorrect;
vector<ll> v;
for (int i = 0; i < n; i++) {
if (inputSeq[i] > n) {
v.push_back(inputSeq[i]);
notCorrect.insert(i);
}
}
int 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:90:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | 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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
2524 KB |
Output is correct |
7 |
Correct |
9 ms |
1628 KB |
Output is correct |
8 |
Correct |
19 ms |
4620 KB |
Output is correct |
9 |
Correct |
8 ms |
1736 KB |
Output is correct |
10 |
Correct |
26 ms |
5492 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
2652 KB |
Output is correct |
7 |
Correct |
6 ms |
1628 KB |
Output is correct |
8 |
Correct |
28 ms |
4692 KB |
Output is correct |
9 |
Correct |
6 ms |
1880 KB |
Output is correct |
10 |
Correct |
36 ms |
5676 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
13 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
448 KB |
Output is correct |
15 |
Correct |
30 ms |
5576 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 |
0 ms |
348 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 |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
412 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Integer 0 violates the range [1, 4637] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Integer 0 violates the range [1, 4637] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
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 |
1 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 |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
39 ms |
4920 KB |
Output is correct |
10 |
Correct |
27 ms |
3928 KB |
Output is correct |
11 |
Correct |
11 ms |
1884 KB |
Output is correct |
12 |
Correct |
13 ms |
2140 KB |
Output is correct |
13 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 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 |
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 |
36 ms |
4956 KB |
Output is correct |
10 |
Correct |
28 ms |
3928 KB |
Output is correct |
11 |
Correct |
13 ms |
1884 KB |
Output is correct |
12 |
Correct |
14 ms |
2336 KB |
Output is correct |
13 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |