# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
589075 |
2022-07-04T09:11:10 Z |
Mamedov |
Gondola (IOI14_gondola) |
C++17 |
|
47 ms |
5964 KB |
#pragma GCC optimize ("O3")
#include "gondola.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int valid(int n, int inputSeq[]) {
set<int>s(inputSeq, inputSeq + n);
if (size(s) < n) return 0;
int shift = -1;
for (int i = 0; i < n; ++i) {
if (inputSeq[i] <= n) {
if (shift == -1) shift = (inputSeq[i] - (i + 1) + n) % n;
else if ((inputSeq[i] - (i + 1) + n) % n != shift) {
return 0;
}
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int shift = 0;
vector<pii>rep;
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] <= n) {
shift = (gondolaSeq[i] - (i + 1) + n) % n;
break;
}
}
for (int i = 0; i < n; ++i) {
if (gondolaSeq[i] > n) {
rep.eb(mpr(gondolaSeq[i], (i + shift) % n + 1));
}
}
rep.eb(mpr(n, n));
int ptr = 0;
sort(all(rep), greater<pii>());
int sz = size(rep);
for (int i = 0; i < sz - 1; ++i) {
for (int j = rep[i].f - 1; j > rep[i + 1].f; --j) {
replacementSeq[ptr++] = j;
}
replacementSeq[ptr++] = rep[i].s;
}
reverse(replacementSeq, replacementSeq + ptr);
return ptr;
}
//----------------------
const int mod = 1e9 + 9;
int binPow(int a, int n) {
if (n == 0) return 1;
if ((n & 1)) return (1ll * a * binPow(a, n - 1)) % mod;
else return binPow((1ll * a * a) % mod, n / 2);
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
vector<int>rep;
for (int i = 0; i < n; ++i) {
if (inputSeq[i] > n) {
rep.eb(inputSeq[i]);
}
}
rep.eb(n);
sort(all(rep), greater<int>());
int sz = size(rep);
int res = 1;
for (int i = 1; i < sz; ++i) {
res = (1ll * res * binPow(i, rep[i - 1] - rep[i] - 1)) % mod;
}
if (sz == n + 1) {
res = (1ll * n * res) % mod;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
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 |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
2436 KB |
Output is correct |
7 |
Correct |
26 ms |
4056 KB |
Output is correct |
8 |
Correct |
18 ms |
4284 KB |
Output is correct |
9 |
Correct |
6 ms |
1480 KB |
Output is correct |
10 |
Correct |
21 ms |
4936 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
2388 KB |
Output is correct |
7 |
Correct |
25 ms |
4128 KB |
Output is correct |
8 |
Correct |
16 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
1492 KB |
Output is correct |
10 |
Correct |
14 ms |
4916 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 |
2280 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
37 ms |
5108 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 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 |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
320 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 |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 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 |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 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 |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
9 ms |
1180 KB |
Output is correct |
13 |
Correct |
13 ms |
1460 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
18 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
280 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
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 |
1 ms |
316 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 |
212 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 |
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 |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
32 ms |
4432 KB |
Output is correct |
10 |
Correct |
25 ms |
3660 KB |
Output is correct |
11 |
Correct |
9 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1884 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
41 ms |
4440 KB |
Output is correct |
10 |
Correct |
24 ms |
3660 KB |
Output is correct |
11 |
Correct |
9 ms |
1492 KB |
Output is correct |
12 |
Correct |
11 ms |
1876 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
40 ms |
5248 KB |
Output is correct |
15 |
Correct |
47 ms |
5964 KB |
Output is correct |
16 |
Correct |
10 ms |
1364 KB |
Output is correct |
17 |
Correct |
36 ms |
4044 KB |
Output is correct |
18 |
Correct |
19 ms |
2476 KB |
Output is correct |