#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];
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]);
}
if (replacementSeq[cnt] == 0) assert(0);
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:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
1116 KB |
Output is correct |
8 |
Correct |
18 ms |
4256 KB |
Output is correct |
9 |
Correct |
6 ms |
1628 KB |
Output is correct |
10 |
Correct |
24 ms |
4944 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
2296 KB |
Output is correct |
7 |
Correct |
6 ms |
1116 KB |
Output is correct |
8 |
Correct |
17 ms |
4188 KB |
Output is correct |
9 |
Correct |
6 ms |
1684 KB |
Output is correct |
10 |
Correct |
23 ms |
4956 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 |
30 ms |
5116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
9 |
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 |
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 |
Runtime error |
0 ms |
604 KB |
Execution killed with signal 6 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
4432 KB |
Output is correct |
10 |
Correct |
28 ms |
3676 KB |
Output is correct |
11 |
Correct |
10 ms |
1884 KB |
Output is correct |
12 |
Correct |
13 ms |
2136 KB |
Output is correct |
13 |
Incorrect |
4 ms |
856 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
36 ms |
4388 KB |
Output is correct |
10 |
Correct |
28 ms |
3676 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 |
- |