# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759773 |
2023-06-16T19:13:33 Z |
raysh07 |
Gondola (IOI14_gondola) |
C++17 |
|
24 ms |
5604 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 9;
int valid(int n, int a[])
{
set <int> st;
for (int i = 0; i < n; i++) st.insert(a[i]);
if (st.size() != n) return 0;
vector <int> b;
for (int i = 0; i < n; i++){
if (a[i] <= n) b.push_back(a[i]);
}
for (int i = 1; i < b.size(); i++){
int need = b[i - 1] + 1;
if (need > n) need = 1;
if (b[i] != need) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int a[], int b[])
{
int mx = 0;
for (int i = 0; i < n; i++) mx = max(mx, a[i]);
int mn = 1e6;
int c[n];
for (int i = 0; i < n; i++) mn = min(mn, a[i]);
if (mn > n){
for (int i = 0; i < n; i++) c[i] = i + 1;
} else {
int p = -1;
for (int i = 0; i < n; i++){
if (a[i] <= n) p = i;
}
c[p] = a[p];
for (int i = p + 1; i < n; i++){
c[i] = c[i - 1] + 1;
if (c[i] > n) c[i] = 1;
}
if (p != 0){
c[0] = c[n - 1] + 1;
if (c[0] > n) c[0] = 1;
for (int i = 1; i < p; i++){
c[i] = c[i - 1] + 1;
if (c[i] > n) c[i] = 1;
}
}
}
int l = 0;
set <pair<int, int>> st;
for (int i = 0; i < n; i++){
if (c[i] != a[i]){
st.insert(make_pair(a[i], i));
}
}
int repl = n + 1;
while (st.size()){
auto u = *st.begin();
b[l++] = c[u.second];
c[u.second] = repl++;
if (c[u.second] == a[u.second]) st.erase(u);
}
return l;
}
//----------------------
long long power(long long x, int y){
if (y==0) return 1;
long long v = power(x, y/2);
v *= v; v %= mod;
if (y & 1) return v * x % mod;
else return v;
}
int countReplacement(int n, int a[])
{
if (!valid(n, a)) return 0;
long long ans = n;
vector <int> v;
for (int i = 0; i < n; i++){
if (a[i] <= n) ans = 1;
else v.push_back(a[i]);
}
sort(v.begin(), v.end());
int choices = v.size();
int curr = n;
for (auto x : v){
int change = x - curr - 1;
ans *= power(choices, change);
ans %= mod;
choices--;
curr = x;
}
return (int)ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:12:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
12 | if (st.size() != n) return 0;
| ~~~~~~~~~~^~~~
gondola.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 1; i < b.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
11 ms |
2712 KB |
Output is correct |
7 |
Correct |
20 ms |
4120 KB |
Output is correct |
8 |
Correct |
15 ms |
4968 KB |
Output is correct |
9 |
Correct |
5 ms |
1748 KB |
Output is correct |
10 |
Correct |
19 ms |
5604 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 |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2732 KB |
Output is correct |
7 |
Correct |
20 ms |
4160 KB |
Output is correct |
8 |
Correct |
19 ms |
4944 KB |
Output is correct |
9 |
Correct |
5 ms |
1708 KB |
Output is correct |
10 |
Correct |
18 ms |
5580 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
10 ms |
2220 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
24 ms |
5488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
308 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 |
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 |
7 ms |
1284 KB |
Output is correct |
12 |
Correct |
8 ms |
1496 KB |
Output is correct |
13 |
Correct |
17 ms |
2884 KB |
Output is correct |
14 |
Correct |
7 ms |
1364 KB |
Output is correct |
15 |
Correct |
19 ms |
3016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |