# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
899251 |
2024-01-05T16:18:34 Z |
aqxa |
Gondola (IOI14_gondola) |
C++17 |
|
65 ms |
5976 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include "gondola.h"
int valid(int n, int a[]) {
set<int> st;
set<int> xs;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
st.insert((a[i] - i + n) % n);
}
if (xs.find(a[i]) != xs.end()) return -1;
xs.insert(a[i]);
}
return (st.size() > 1 ? 0 : 1);
}
//----------------------
int replacement(int n, int a[], int ans[]) {
int v = 1;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
v = (a[i] - i + n) % n;
}
}
vector<int> b(n);
for (int i = 0; i < n; ++i) {
b[i] = (v + i + n) % n;
if (b[i] == 0) b[i] = n;
}
set<pair<int, int>> xs;
for (int i = 0; i < n; ++i) {
if (a[i] > n) xs.insert({a[i], i});
}
int l = 0, last = n;
for (auto [x, p]: xs) {
while (b[p] < x) {
ans[l++] = b[p];
b[p] = ++last;
}
}
// for (int i = 0; i < l; ++i) {
// cout << ans[i] << " \n"[i + 1 == l];
// }
return l;
}
//----------------------
const int M = 1e9 + 9;
ll pw(ll x, ll e) {
ll res = 1;
ll cur = x;
for (int b = 0; b < 30; ++b) {
if ((1LL << b) & e) {
res = (res * cur) % M;
}
cur = (cur * cur) % M;
}
return res;
}
int countReplacement(int n, int a[]) {
if (!valid(n, a)) return -1;
int ok = 0, v = 1;
ll cp = 0;
set<ll> st;
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
v = (a[i] - i + n) % n;
ok = 1;
} else {
cp++;
st.insert(a[i]);
}
}
ll ans = 1;
ll last = n;
for (ll x: st) {
ll cnt = x - last - 1;
ans = (ans * (pw(cp, cnt))) % M;
cp--;
last = x;
}
if (!ok) ans = (ans * n) % M;
return (int) (ans % M);
}
// int32_t main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// int t;
// cin >> t;
// while (t--) {
// int n;
// cin >> n;
// int a[n];
// for (int i = 0; i < n; ++i) cin >> a[i];
// cout << countReplacement(n, a) << "\n";
// }
// return 0;
// }
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:73:14: warning: variable 'v' set but not used [-Wunused-but-set-variable]
73 | int ok = 0, v = 1;
| ^
# |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 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 |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
10 ms |
2396 KB |
Output is correct |
7 |
Incorrect |
7 ms |
1116 KB |
Integer -1 violates the range [0, 1] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2512 KB |
Output is correct |
7 |
Incorrect |
6 ms |
1116 KB |
Integer -1 violates the range [0, 1] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
1 ms |
444 KB |
Output is correct |
3 |
Correct |
1 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 |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
444 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 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 |
440 KB |
Output is correct |
6 |
Correct |
0 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
7 ms |
1372 KB |
Output is correct |
12 |
Correct |
8 ms |
1628 KB |
Output is correct |
13 |
Correct |
16 ms |
2772 KB |
Output is correct |
14 |
Correct |
7 ms |
1372 KB |
Output is correct |
15 |
Correct |
17 ms |
3164 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 |
# |
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 |
444 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
44 ms |
4636 KB |
Output is correct |
10 |
Correct |
35 ms |
3904 KB |
Output is correct |
11 |
Correct |
13 ms |
1628 KB |
Output is correct |
12 |
Correct |
16 ms |
1968 KB |
Output is correct |
13 |
Correct |
4 ms |
820 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 |
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 |
43 ms |
4660 KB |
Output is correct |
10 |
Correct |
33 ms |
3676 KB |
Output is correct |
11 |
Correct |
13 ms |
1684 KB |
Output is correct |
12 |
Correct |
16 ms |
1884 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
57 ms |
5508 KB |
Output is correct |
15 |
Correct |
65 ms |
5976 KB |
Output is correct |
16 |
Correct |
10 ms |
1376 KB |
Output is correct |
17 |
Correct |
41 ms |
4184 KB |
Output is correct |
18 |
Correct |
22 ms |
2404 KB |
Output is correct |