Submission #75814467
Source Code Expand
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define rep(i, s, e) for (ll i = (s); i <= (e); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = array<ll, 2>;
ll n, m, a[1010101], b[1010101], p[1010101], j, cnt[1010101];
vector<ll> res;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
rep(i, 1, n) cin >> a[i], cnt[a[i]]++;
rep(i, 1, m) cin >> b[i];
rep(i, 2, m) {
while (j > 0 && b[i] != b[j + 1])
j = p[j];
if (b[i] == b[j + 1])
p[i] = ++j;
}
rep(i, 1, p[m]) {
if (!cnt[b[i]])
break;
cnt[b[i]]--;
res.push_back(b[i]);
}
while (1) {
bool fl = 0;
rep(i, p[m] + 1, m) {
if (!cnt[b[i]]) {
fl = 1;
break;
}
cnt[b[i]]--;
res.push_back(b[i]);
}
if (fl)
break;
}
rep(i, 0, 1'000'000) while (cnt[i]) res.push_back(i), cnt[i]--;
for (ll i : res)
cout << i << ' ';
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Rearrangement |
| User | iAi |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1028 Byte |
| Status | AC |
| Exec Time | 132 ms |
| Memory | 46356 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 | 2 ms | 3488 KiB |
| 00-sample-002.txt | AC | 2 ms | 3660 KiB |
| 01-003.txt | AC | 2 ms | 3476 KiB |
| 01-004.txt | AC | 2 ms | 3488 KiB |
| 01-005.txt | AC | 2 ms | 3592 KiB |
| 01-006.txt | AC | 2 ms | 3644 KiB |
| 01-007.txt | AC | 2 ms | 3592 KiB |
| 01-008.txt | AC | 2 ms | 3556 KiB |
| 01-009.txt | AC | 64 ms | 22548 KiB |
| 01-010.txt | AC | 4 ms | 4044 KiB |
| 01-011.txt | AC | 10 ms | 5524 KiB |
| 01-012.txt | AC | 15 ms | 7124 KiB |
| 01-013.txt | AC | 23 ms | 10108 KiB |
| 01-014.txt | AC | 69 ms | 29724 KiB |
| 01-015.txt | AC | 76 ms | 34580 KiB |
| 01-016.txt | AC | 125 ms | 41236 KiB |
| 01-017.txt | AC | 70 ms | 28948 KiB |
| 01-018.txt | AC | 110 ms | 34328 KiB |
| 01-019.txt | AC | 55 ms | 27108 KiB |
| 01-020.txt | AC | 72 ms | 30228 KiB |
| 01-021.txt | AC | 64 ms | 27920 KiB |
| 01-022.txt | AC | 59 ms | 29904 KiB |
| 01-023.txt | AC | 54 ms | 27188 KiB |
| 01-024.txt | AC | 107 ms | 34064 KiB |
| 01-025.txt | AC | 62 ms | 27268 KiB |
| 01-026.txt | AC | 77 ms | 36012 KiB |
| 01-027.txt | AC | 63 ms | 27192 KiB |
| 01-028.txt | AC | 69 ms | 35680 KiB |
| 01-029.txt | AC | 61 ms | 27232 KiB |
| 01-030.txt | AC | 58 ms | 27284 KiB |
| 01-031.txt | AC | 106 ms | 46356 KiB |
| 01-032.txt | AC | 69 ms | 28180 KiB |
| 01-033.txt | AC | 88 ms | 32788 KiB |
| 01-034.txt | AC | 132 ms | 38932 KiB |
| 01-035.txt | AC | 132 ms | 38932 KiB |
| 01-036.txt | AC | 128 ms | 38936 KiB |
| 01-037.txt | AC | 86 ms | 32532 KiB |
| 01-038.txt | AC | 83 ms | 33560 KiB |
| 01-039.txt | AC | 99 ms | 37652 KiB |
| 01-040.txt | AC | 98 ms | 37912 KiB |
| 01-041.txt | AC | 81 ms | 34840 KiB |
| 01-042.txt | AC | 96 ms | 36372 KiB |
| 01-043.txt | AC | 74 ms | 33308 KiB |
| 01-044.txt | AC | 91 ms | 34836 KiB |
| 01-045.txt | AC | 75 ms | 33560 KiB |
| 01-046.txt | AC | 87 ms | 33048 KiB |
| 01-047.txt | AC | 60 ms | 21008 KiB |
| 01-048.txt | AC | 62 ms | 27664 KiB |
| 01-049.txt | AC | 73 ms | 30736 KiB |
| 01-050.txt | AC | 68 ms | 29972 KiB |