# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1065678 | 2024-08-19T10:51:58 Z | andrei_iorgulescu | 곤돌라 (IOI14_gondola) | C++14 | 37 ms | 11356 KB |
#include <bits/stdc++.h> #include "gondola.h" #warning That's not FB, that's my FB using namespace std; int valid(int n, int inputSeq[]) { for (int i = 0; i < n; i++) inputSeq[i]--; int shift = -1; set<int> ele; for (int i = 0; i < n; i++) ele.insert(inputSeq[i]); if (ele.size() != n) return 0; for (int i = 0; i < n; i++) { if (inputSeq[i] < n) { int cur_shift = (n + inputSeq[i] - i) % n; if (shift == -1) shift = cur_shift; else if (shift != cur_shift) return 0; } } return 1; } int replacement(int n, int gondolaSequence[], int replacementSeq[]) { for (int i = 0; i < n; i++) gondolaSequence[i]--; int mxe = 0; for (int i = 0; i < n; i++) mxe = max(mxe, gondolaSequence[i]); vector<int> pos(mxe + 5), ans(mxe + 5); for (int i = 0; i <= mxe; i++) pos[i] = -1; for (int i = 0; i < n; i++) pos[gondolaSequence[i]] = i; set<int> spatii; for (int i = mxe; i >= 0; i--) { if (pos[i] == -1) ans[i] = *spatii.begin(); else ans[i] = pos[i], spatii.insert(pos[i]); } int shift = 0; for (int i = 0; i < n; i++) { if (gondolaSequence[i] < n) { shift = (n + gondolaSequence[i] - i) % n; } } vector<vector<int>> lol(n); for (int i = 0; i < n; i++) lol[i].push_back((i + shift) % n); for (int i = n; i <= mxe; i++) lol[ans[i]].push_back(i); vector<int> cur(n); for (int i = n; i <= mxe; i++) { replacementSeq[i - n] = lol[ans[i]][cur[ans[i]]]; cur[ans[i]]++; } for (int i = 0; i <= mxe - n; i++) replacementSeq[i]++; return mxe - n + 1; } int modulo = (int)1e9 + 9; int lgpow(int x, int y) { int z = 1; while (y != 0) { if (y % 2 == 1) z = 1ll * z * x % modulo; x = 1ll * x * x % modulo; y /= 2; } return z; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; //for (int i = 0; i < n; i++) // inputSeq[i]--; bool multi_n = true; for (int i = 0; i < n; i++) if (inputSeq[i] < n) multi_n = false; vector<int> fx; for (int i = 0; i < n; i++) if (inputSeq[i] >= n) fx.push_back(inputSeq[i]); sort(fx.begin(), fx.end()); reverse(fx.begin(), fx.end()); int ans = 1; for (int i = 0; i < fx.size(); i++) { if (i + 1 < fx.size()) { int gap = fx[i] - fx[i + 1] - 1; ans = 1ll * ans * lgpow(i + 1, gap) % modulo; } else { int gap = fx[i] - n; ans = 1ll * ans * lgpow(i + 1, gap) % modulo; } } if (multi_n) ans = 1ll * ans * n % modulo; return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 8 ms | 2396 KB | Output is correct |
7 | Correct | 19 ms | 4272 KB | Output is correct |
8 | Correct | 15 ms | 4440 KB | Output is correct |
9 | Correct | 6 ms | 1628 KB | Output is correct |
10 | Correct | 20 ms | 5016 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 444 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 440 KB | Output is correct |
6 | Correct | 8 ms | 2396 KB | Output is correct |
7 | Correct | 20 ms | 4312 KB | Output is correct |
8 | Correct | 13 ms | 4444 KB | Output is correct |
9 | Correct | 5 ms | 1736 KB | Output is correct |
10 | Correct | 18 ms | 4956 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 10 ms | 2392 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 26 ms | 5304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 0 ms | 444 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 | 26 ms | 10072 KB | Output is correct |
12 | Correct | 23 ms | 11356 KB | Output is correct |
13 | Correct | 19 ms | 5852 KB | Output is correct |
14 | Correct | 20 ms | 10072 KB | Output is correct |
15 | Correct | 18 ms | 5180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 440 KB | Output is correct |
2 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 26 ms | 4444 KB | Output is correct |
10 | Correct | 21 ms | 3932 KB | Output is correct |
11 | Correct | 7 ms | 1624 KB | Output is correct |
12 | Correct | 9 ms | 1884 KB | Output is correct |
13 | Correct | 2 ms | 756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 352 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 440 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 352 KB | Output is correct |
8 | Correct | 0 ms | 444 KB | Output is correct |
9 | Correct | 31 ms | 4804 KB | Output is correct |
10 | Correct | 20 ms | 3928 KB | Output is correct |
11 | Correct | 7 ms | 1628 KB | Output is correct |
12 | Correct | 9 ms | 1936 KB | Output is correct |
13 | Correct | 2 ms | 604 KB | Output is correct |
14 | Correct | 32 ms | 5252 KB | Output is correct |
15 | Correct | 37 ms | 5968 KB | Output is correct |
16 | Correct | 6 ms | 1372 KB | Output is correct |
17 | Correct | 24 ms | 4284 KB | Output is correct |
18 | Correct | 13 ms | 2392 KB | Output is correct |