# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1064366 |
2024-08-18T11:54:45 Z |
Blagoj |
Gondola (IOI14_gondola) |
C++17 |
|
41 ms |
4960 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<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]);
}
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: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++) {
| ~~^~~~~~~~~~
# |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
10 ms |
2368 KB |
Output is correct |
7 |
Correct |
6 ms |
976 KB |
Output is correct |
8 |
Correct |
18 ms |
4188 KB |
Output is correct |
9 |
Correct |
6 ms |
1628 KB |
Output is correct |
10 |
Correct |
24 ms |
4956 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
2396 KB |
Output is correct |
7 |
Correct |
5 ms |
1116 KB |
Output is correct |
8 |
Correct |
19 ms |
4268 KB |
Output is correct |
9 |
Correct |
7 ms |
1624 KB |
Output is correct |
10 |
Correct |
28 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 |
2176 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
32 ms |
4932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Integer 0 violates the range [1, 4637] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Integer 0 violates the range [1, 4637] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
444 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
4960 KB |
Output is correct |
10 |
Correct |
28 ms |
3944 KB |
Output is correct |
11 |
Correct |
12 ms |
1884 KB |
Output is correct |
12 |
Correct |
14 ms |
2244 KB |
Output is correct |
13 |
Incorrect |
4 ms |
860 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
41 ms |
4812 KB |
Output is correct |
10 |
Correct |
29 ms |
3932 KB |
Output is correct |
11 |
Correct |
11 ms |
1884 KB |
Output is correct |
12 |
Correct |
14 ms |
2208 KB |
Output is correct |
13 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |