# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718218 | 2023-04-03T16:44:10 Z | thimote75 | Gondola (IOI14_gondola) | C++14 | 88 ms | 5932 KB |
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]) { set<int> omega; for (int i = 0; i < n; i ++) omega.insert(inputSeq[i]); if (omega.size() != n) return 0; int jStart = -1; for (int i = 0; i < n; i ++) { if (inputSeq[i] > n) continue ; jStart = i; break; } if (jStart == -1) return 1; int start = jStart - inputSeq[jStart] + 1; if (start < 0) start += n; for (int mu = 0; mu < n; mu ++) { int nu = (start + mu); if (nu >= n) nu -= n; if (inputSeq[nu] > n) continue ; if (inputSeq[nu] != mu + 1) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int maxValue = 0; int maxPos = -1; int jStart = -1; for (int i = 0; i < n; i ++) { if (gondolaSeq[i] > maxValue) { maxValue = gondolaSeq[i]; maxPos = i; } if (gondolaSeq[i] <= n) { jStart = i; } } int start = 0; if (jStart != -1) { start = jStart - gondolaSeq[jStart] + 1; if (start < 0) start += n; } int length = maxValue - n; for (int i = 0; i < length; i ++) { replacementSeq[i] = -1; } for (int i = 0; i < n; i ++) { if (gondolaSeq[i] > n && gondolaSeq[i] != maxValue) { replacementSeq[gondolaSeq[i] - n - 1] = (n + i - start) % n + 1; } } int last = (n + maxPos - start) % n + 1; for (int i = 0; i < length; i ++) { int value = i + n + 1; if (replacementSeq[i] != -1) continue ; replacementSeq[i] = last; last = value; } return length; } //---------------------- #define num long long const num MOD = 1e9 + 9; num h_table[20]; num pw (num x, int k) { h_table[0] = x; for (int h = 1; (1 << h) <= k; h ++) { h_table[h] = h_table[h - 1] * h_table[h - 1]; h_table[h] %= MOD; } num res = 1; for (int i = 0; (1 << i) <= k; i ++) { if (((1 << i) & k) == 0) continue ; res *= h_table[i]; res %= MOD; } return res; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; bool includes_old = false; for (int i = 0; i < n; i ++) if (inputSeq[i] <= n) includes_old = true; int maxValue = 0; set<int> omega; for (int i = 0; i < n; i ++) { if (inputSeq[i] > n) omega.insert(inputSeq[i]); maxValue = max(maxValue, inputSeq[i]); } num result = 1; int delta = 0; int last = n; for (int alpha : omega) { int delta_v = alpha - last - 1; result *= pw(omega.size() - delta, delta_v); result %= MOD; last = alpha; delta ++; } if (!includes_old) { result *= n; result %= MOD; } return (int) result; }
Compilation message
# | 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 | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | 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 | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 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 | 11 ms | 2132 KB | Output is correct |
7 | Correct | 25 ms | 3612 KB | Output is correct |
8 | Correct | 19 ms | 3924 KB | Output is correct |
9 | Correct | 6 ms | 1364 KB | Output is correct |
10 | Correct | 23 ms | 4504 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 | 0 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 | 10 ms | 2208 KB | Output is correct |
7 | Correct | 25 ms | 3664 KB | Output is correct |
8 | Correct | 21 ms | 3924 KB | Output is correct |
9 | Correct | 6 ms | 1364 KB | Output is correct |
10 | Correct | 22 ms | 4428 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 13 ms | 2004 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 31 ms | 4676 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 |
# | 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 | 0 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 | 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 |
# | 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 | 0 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 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 | 596 KB | Output is correct |
12 | Correct | 7 ms | 596 KB | Output is correct |
13 | Correct | 11 ms | 1108 KB | Output is correct |
14 | Correct | 7 ms | 596 KB | Output is correct |
15 | Correct | 18 ms | 2052 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 | 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 | 0 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 | 0 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 | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 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 | 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 |
9 | Correct | 42 ms | 4000 KB | Output is correct |
10 | Correct | 34 ms | 3372 KB | Output is correct |
11 | Correct | 12 ms | 1444 KB | Output is correct |
12 | Correct | 17 ms | 1692 KB | Output is correct |
13 | Correct | 3 ms | 644 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 | 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 | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 44 ms | 3912 KB | Output is correct |
10 | Correct | 34 ms | 3388 KB | Output is correct |
11 | Correct | 12 ms | 1440 KB | Output is correct |
12 | Correct | 15 ms | 1660 KB | Output is correct |
13 | Correct | 3 ms | 596 KB | Output is correct |
14 | Correct | 64 ms | 4472 KB | Output is correct |
15 | Correct | 88 ms | 5932 KB | Output is correct |
16 | Correct | 10 ms | 1364 KB | Output is correct |
17 | Correct | 41 ms | 4148 KB | Output is correct |
18 | Correct | 22 ms | 2388 KB | Output is correct |