# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1064423 |
2024-08-18T12:33:24 Z |
Blagoj |
Gondola (IOI14_gondola) |
C++17 |
|
43 ms |
6740 KB |
#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<ll> ans;
bool kurac = 0;
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) {
kurac = 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 = {n};
ll sz = 0;
for (int i = 0; i < n; i++) {
if (inputSeq[i] > n) {
v.push_back(inputSeq[i]);
sz++;
}
}
sort(all(v));
ll cnt = 1;
if (kurac) cnt = n;
for (int i = 1; i < v.size(); i++) {
ll time = v[i] - v[i - 1] - 1;
cnt = (cnt * expo(sz, time)) % MOD;
sz--;
}
return cnt;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:97:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
2652 KB |
Output is correct |
7 |
Correct |
6 ms |
1372 KB |
Output is correct |
8 |
Correct |
18 ms |
4444 KB |
Output is correct |
9 |
Correct |
6 ms |
1624 KB |
Output is correct |
10 |
Correct |
23 ms |
5192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
12 ms |
2572 KB |
Output is correct |
7 |
Correct |
6 ms |
1372 KB |
Output is correct |
8 |
Correct |
18 ms |
4444 KB |
Output is correct |
9 |
Correct |
5 ms |
1628 KB |
Output is correct |
10 |
Correct |
24 ms |
5208 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
11 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
30 ms |
5372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
20 ms |
5664 KB |
Output is correct |
12 |
Correct |
25 ms |
6320 KB |
Output is correct |
13 |
Correct |
23 ms |
3752 KB |
Output is correct |
14 |
Correct |
27 ms |
5760 KB |
Output is correct |
15 |
Correct |
22 ms |
3920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
444 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
428 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 |
440 KB |
Output is correct |
8 |
Correct |
0 ms |
440 KB |
Output is correct |
9 |
Correct |
30 ms |
5084 KB |
Output is correct |
10 |
Correct |
24 ms |
4440 KB |
Output is correct |
11 |
Correct |
9 ms |
1884 KB |
Output is correct |
12 |
Correct |
11 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 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 |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
5236 KB |
Output is correct |
10 |
Correct |
24 ms |
4188 KB |
Output is correct |
11 |
Correct |
9 ms |
1748 KB |
Output is correct |
12 |
Correct |
10 ms |
2140 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
37 ms |
5932 KB |
Output is correct |
15 |
Correct |
43 ms |
6740 KB |
Output is correct |
16 |
Correct |
7 ms |
1624 KB |
Output is correct |
17 |
Correct |
27 ms |
4692 KB |
Output is correct |
18 |
Correct |
15 ms |
3164 KB |
Output is correct |