Submission #75816124
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// https://github.com/skrewbar/cp-templates
#define all(v) (v).begin(), (v).end()
#define compress(v) \
sort(all(v)); \
v.erase(unique(all(v)), (v).end())
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define by_desc(x) [](const auto& a, const auto& b) { return a.x > b.x; }
template <typename T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool minimize(T& target, T candidate) {
return target > candidate ? (target = candidate, true) : false;
}
template <typename T>
bool maximize(T& target, T candidate) {
return target < candidate ? (target = candidate, true) : false;
}
int A[1010101], B[1010101];
int fail[1010101];
int cnt[1010101];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> A[i];
cnt[A[i]]++;
}
for (int i = 0; i < M; i++)
cin >> B[i];
for (int i = 1, j = 0; i < M; i++) {
while (j > 0 and B[i] != B[j])
j = fail[j - 1];
if (B[i] == B[j])
fail[i] = ++j;
}
int patternLen = M - fail[M - 1];
for (int i = 0, j = 0; i < N; i++) {
if (cnt[B[j]]) {
cout << B[j] << ' ';
cnt[B[j]]--;
if (++j >= patternLen)
j = 0;
} else
break;
}
for (int v = 0; v <= 1'000'000; v++) {
for (int c = 0; c < cnt[v]; c++)
cout << v << ' ';
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Rearrangement |
| User | skuru |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1638 Byte |
| Status | AC |
| Exec Time | 118 ms |
| Memory | 22952 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 | 3528 KiB |
| 00-sample-002.txt | AC | 2 ms | 3412 KiB |
| 01-003.txt | AC | 2 ms | 3656 KiB |
| 01-004.txt | AC | 2 ms | 3528 KiB |
| 01-005.txt | AC | 2 ms | 3368 KiB |
| 01-006.txt | AC | 2 ms | 3396 KiB |
| 01-007.txt | AC | 2 ms | 3372 KiB |
| 01-008.txt | AC | 2 ms | 3548 KiB |
| 01-009.txt | AC | 59 ms | 10920 KiB |
| 01-010.txt | AC | 3 ms | 3396 KiB |
| 01-011.txt | AC | 9 ms | 3832 KiB |
| 01-012.txt | AC | 13 ms | 4240 KiB |
| 01-013.txt | AC | 21 ms | 4744 KiB |
| 01-014.txt | AC | 61 ms | 14032 KiB |
| 01-015.txt | AC | 69 ms | 15788 KiB |
| 01-016.txt | AC | 117 ms | 20396 KiB |
| 01-017.txt | AC | 63 ms | 13224 KiB |
| 01-018.txt | AC | 100 ms | 16808 KiB |
| 01-019.txt | AC | 47 ms | 11204 KiB |
| 01-020.txt | AC | 66 ms | 13484 KiB |
| 01-021.txt | AC | 58 ms | 11940 KiB |
| 01-022.txt | AC | 51 ms | 12652 KiB |
| 01-023.txt | AC | 47 ms | 11204 KiB |
| 01-024.txt | AC | 99 ms | 16804 KiB |
| 01-025.txt | AC | 55 ms | 11484 KiB |
| 01-026.txt | AC | 70 ms | 16280 KiB |
| 01-027.txt | AC | 57 ms | 11416 KiB |
| 01-028.txt | AC | 59 ms | 15980 KiB |
| 01-029.txt | AC | 55 ms | 11352 KiB |
| 01-030.txt | AC | 51 ms | 11372 KiB |
| 01-031.txt | AC | 95 ms | 22952 KiB |
| 01-032.txt | AC | 63 ms | 12460 KiB |
| 01-033.txt | AC | 81 ms | 16044 KiB |
| 01-034.txt | AC | 117 ms | 19112 KiB |
| 01-035.txt | AC | 116 ms | 19116 KiB |
| 01-036.txt | AC | 118 ms | 19116 KiB |
| 01-037.txt | AC | 79 ms | 16040 KiB |
| 01-038.txt | AC | 74 ms | 17320 KiB |
| 01-039.txt | AC | 86 ms | 18604 KiB |
| 01-040.txt | AC | 89 ms | 18596 KiB |
| 01-041.txt | AC | 71 ms | 17832 KiB |
| 01-042.txt | AC | 85 ms | 17836 KiB |
| 01-043.txt | AC | 66 ms | 16548 KiB |
| 01-044.txt | AC | 82 ms | 17320 KiB |
| 01-045.txt | AC | 67 ms | 16812 KiB |
| 01-046.txt | AC | 78 ms | 16296 KiB |
| 01-047.txt | AC | 54 ms | 10408 KiB |
| 01-048.txt | AC | 56 ms | 14000 KiB |
| 01-049.txt | AC | 65 ms | 15276 KiB |
| 01-050.txt | AC | 61 ms | 15272 KiB |