# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
809014 |
2023-08-05T14:11:49 Z |
Kerim |
Gondola (IOI14_gondola) |
C++17 |
|
54 ms |
6024 KB |
#include "gondola.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
bool is_unique(int n, int arr[]){
set<int> s;
for (int i = 0; i < n; i++){
if (s.count(arr[i]))
return false;
s.insert(arr[i]);
}
return true;
}
vector<int> beginning(int n, int pos, int value){
vector<int> arr(n);
for (int i = 0; i < n; i++){
arr[pos] = value+1;
pos = (pos+1)%n;
value = (value+1)%n;
}
return arr;
}
int valid(int n, int arr[]){
if (!is_unique(n, arr))
return false;
int pos = -1;
for (int i = 0; i < n; i++)
if (arr[i] <= n)
pos = i;
if (pos == -1)
return 1;
vector<int> original = beginning(n, pos, arr[pos]-1);
for (int i = 0; i < n; i++)
if (arr[i] <= n and arr[i] != original[i])
return 0;
return 1;
}
//----------------------
int replacement(int n, int arr[], int answer[]){
assert(valid(n, arr));
int max_value = 0, pos = -1;
int min_value = INT_MAX;
for (int i = 0; i < n; i++){
max_value = max(max_value, arr[i]);
min_value = min(min_value, arr[i]);
if (arr[i] <= n)
pos = i;
}
if (max_value <= n)
return 0;
vector<int> original(n);
for (int i = 0; i < n; i++)
original[i] = i+1;
if (min_value <= n)
original = beginning(n, pos, arr[pos]-1);
vector<int> idx;
for (int i = 0; i < n; i++)
if (arr[i] > n)
idx.push_back(i);
sort(idx.begin(), idx.end(), [&](int x, int y){
return (arr[x] < arr[y]);
});
int position = 0, last = n+1;
for (int i = 0; i < int(idx.size()); i++){
answer[position++] = original[idx[i]];
while (last < arr[idx[i]])
answer[position++] = last++;
last += 1;
}
return position;
}
//----------------------
const int MOD = 1e9+9;
int mod(ll x){
return (x%MOD);
}
int Fe(int x, int y){
if(!y)
return 1;
int h = Fe(x, y/2);
h = mod(h*1LL*h);
if (y&1)
h = mod(h*1LL*x);
return h;
}
int countReplacement(int n, int arr[]){
if (!valid(n, arr))
return 0;
vector<int> idx;
for (int i = 0; i < n; i++)
if (arr[i] > n)
idx.push_back(i);
sort(idx.begin(), idx.end(), [&](int x, int y){
return (arr[x] < arr[y]);
});
int free_n = int(idx.size()), ans = 1, last = n;
if (free_n == n)
ans = n;
for (int i = 0; i < int(idx.size()); i++){
int cur = arr[idx[i]];
ans = mod(ans * 1LL * Fe(free_n, cur - last - 1));
last = cur;
free_n -= 1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2424 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
20 ms |
4264 KB |
Output is correct |
9 |
Correct |
6 ms |
1492 KB |
Output is correct |
10 |
Correct |
25 ms |
4900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
12 ms |
2404 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
21 ms |
4236 KB |
Output is correct |
9 |
Correct |
6 ms |
1588 KB |
Output is correct |
10 |
Correct |
25 ms |
4976 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
12 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
5108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
26 ms |
4756 KB |
Output is correct |
12 |
Correct |
27 ms |
5324 KB |
Output is correct |
13 |
Correct |
21 ms |
2892 KB |
Output is correct |
14 |
Correct |
25 ms |
4692 KB |
Output is correct |
15 |
Correct |
19 ms |
2880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
33 ms |
4512 KB |
Output is correct |
10 |
Correct |
27 ms |
3768 KB |
Output is correct |
11 |
Correct |
10 ms |
1492 KB |
Output is correct |
12 |
Correct |
13 ms |
1796 KB |
Output is correct |
13 |
Correct |
3 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
34 ms |
4408 KB |
Output is correct |
10 |
Correct |
27 ms |
3760 KB |
Output is correct |
11 |
Correct |
9 ms |
1596 KB |
Output is correct |
12 |
Correct |
12 ms |
1812 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
39 ms |
5296 KB |
Output is correct |
15 |
Correct |
54 ms |
6024 KB |
Output is correct |
16 |
Correct |
7 ms |
1364 KB |
Output is correct |
17 |
Correct |
29 ms |
4052 KB |
Output is correct |
18 |
Correct |
16 ms |
2424 KB |
Output is correct |