Submission #75816018
Source Code Expand
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
const array<int, 2> mod {(int)1e9 + 7, (int)1e9 + 9};
const int key = 39393939;
array<array<int, 1010101>, 2> P, H;
array<int, 1010101> cnt, B, ans;
int N, M, K;
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> N >> M;
P[0][0] = P[1][0] = 1;
for (int i = 1; i <= M; i++) {
P[0][i] = P[0][i - 1] * key % mod[0];
P[1][i] = P[1][i - 1] * key % mod[1];
}
for (int i = 0; i < N; i++) {
int a;
cin >> a;
cnt[a]++;
}
for (int i = 1; i <= M; i++) {
cin >> B[i];
H[0][i] = (H[0][i - 1] + B[i] * P[0][i]) % mod[0];
H[1][i] = (H[1][i - 1] + B[i] * P[1][i]) % mod[1];
}
for (int j = M - 1; ; j--) {
if (H[0][j] * P[0][M - j] % mod[0] == (mod[0] + H[0][M] - H[0][M - j]) % mod[0]
&& H[1][j] * P[1][M - j] % mod[1] == (mod[1] + H[1][M] - H[1][M - j]) % mod[1]) {
K = j;
break;
}
}
for (int i = 0, j = 1; i < N; i++, j++) {
if (j > M) {
j = K + 1;
}
if (cnt[B[j]]--) {
ans[i] = B[j];
}
else {
for (int v = 0; v <= (int)1e6; v++) {
for (int _ = 0; _ < cnt[v]; _++) {
ans[i++] = v;
}
}
break;
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Rearrangement |
| User | fortunatly |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1356 Byte |
| Status | AC |
| Exec Time | 153 ms |
| Memory | 62128 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt, 01-048.txt, 01-049.txt, 01-050.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 3 ms | 3616 KiB |
| 00-sample-002.txt | AC | 1 ms | 3708 KiB |
| 01-003.txt | AC | 1 ms | 3540 KiB |
| 01-004.txt | AC | 2 ms | 3504 KiB |
| 01-005.txt | AC | 2 ms | 3684 KiB |
| 01-006.txt | AC | 2 ms | 3616 KiB |
| 01-007.txt | AC | 1 ms | 3660 KiB |
| 01-008.txt | AC | 1 ms | 3520 KiB |
| 01-009.txt | AC | 64 ms | 14760 KiB |
| 01-010.txt | AC | 4 ms | 3560 KiB |
| 01-011.txt | AC | 10 ms | 4404 KiB |
| 01-012.txt | AC | 14 ms | 5044 KiB |
| 01-013.txt | AC | 22 ms | 6220 KiB |
| 01-014.txt | AC | 71 ms | 21928 KiB |
| 01-015.txt | AC | 85 ms | 37288 KiB |
| 01-016.txt | AC | 146 ms | 59048 KiB |
| 01-017.txt | AC | 72 ms | 21160 KiB |
| 01-018.txt | AC | 116 ms | 37292 KiB |
| 01-019.txt | AC | 54 ms | 19200 KiB |
| 01-020.txt | AC | 76 ms | 26060 KiB |
| 01-021.txt | AC | 66 ms | 19888 KiB |
| 01-022.txt | AC | 63 ms | 25984 KiB |
| 01-023.txt | AC | 55 ms | 19208 KiB |
| 01-024.txt | AC | 117 ms | 37292 KiB |
| 01-025.txt | AC | 63 ms | 18996 KiB |
| 01-026.txt | AC | 87 ms | 43188 KiB |
| 01-027.txt | AC | 64 ms | 19368 KiB |
| 01-028.txt | AC | 78 ms | 41496 KiB |
| 01-029.txt | AC | 63 ms | 19136 KiB |
| 01-030.txt | AC | 58 ms | 19032 KiB |
| 01-031.txt | AC | 122 ms | 61868 KiB |
| 01-032.txt | AC | 70 ms | 20392 KiB |
| 01-033.txt | AC | 90 ms | 28328 KiB |
| 01-034.txt | AC | 151 ms | 62116 KiB |
| 01-035.txt | AC | 152 ms | 62128 KiB |
| 01-036.txt | AC | 153 ms | 62124 KiB |
| 01-037.txt | AC | 96 ms | 38568 KiB |
| 01-038.txt | AC | 92 ms | 36268 KiB |
| 01-039.txt | AC | 111 ms | 51376 KiB |
| 01-040.txt | AC | 113 ms | 51628 KiB |
| 01-041.txt | AC | 86 ms | 35496 KiB |
| 01-042.txt | AC | 110 ms | 47784 KiB |
| 01-043.txt | AC | 79 ms | 29096 KiB |
| 01-044.txt | AC | 104 ms | 44200 KiB |
| 01-045.txt | AC | 78 ms | 29608 KiB |
| 01-046.txt | AC | 94 ms | 39344 KiB |
| 01-047.txt | AC | 61 ms | 14056 KiB |
| 01-048.txt | AC | 64 ms | 20900 KiB |
| 01-049.txt | AC | 75 ms | 22960 KiB |
| 01-050.txt | AC | 74 ms | 22188 KiB |