From e58e668926700d270bc43183c669dbc07219ba65 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 25 Feb 2025 17:15:58 +0900 Subject: [PATCH] =?UTF-8?q?[20250225]=20BOJ=20/=20G4=20/=20=EC=82=AC?= =?UTF-8?q?=EC=A0=84=20=EC=88=9C=20=EC=B5=9C=EB=8C=80=20=EA=B3=B5=ED=86=B5?= =?UTF-8?q?=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=97=B4=20/=20=EA=B6=8C?= =?UTF-8?q?=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\266\204 \354\210\230\354\227\264.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "khj20006/202502/25 BOJ G4 \354\202\254\354\240\204 \354\210\234 \354\265\234\353\214\200 \352\263\265\355\206\265 \353\266\200\353\266\204 \354\210\230\354\227\264.md" diff --git "a/khj20006/202502/25 BOJ G4 \354\202\254\354\240\204 \354\210\234 \354\265\234\353\214\200 \352\263\265\355\206\265 \353\266\200\353\266\204 \354\210\230\354\227\264.md" "b/khj20006/202502/25 BOJ G4 \354\202\254\354\240\204 \354\210\234 \354\265\234\353\214\200 \352\263\265\355\206\265 \353\266\200\353\266\204 \354\210\230\354\227\264.md" new file mode 100644 index 00000000..0b0a8307 --- /dev/null +++ "b/khj20006/202502/25 BOJ G4 \354\202\254\354\240\204 \354\210\234 \354\265\234\353\214\200 \352\263\265\355\206\265 \353\266\200\353\266\204 \354\210\230\354\227\264.md" @@ -0,0 +1,42 @@ +```cpp + +#include +#include +using namespace std; + +int main() +{ + cin.tie(0)->sync_with_stdio(0); + + int N, M; + cin >> N; + vector A(N); + for (int &i : A) cin >> i; + cin >> M; + vector B(M); + for (int &i : B) cin >> i; + + vector R; + int idxA = 0, idxB = 0; + while (idxA < N && idxB < M) { + bool suc = 0; + for (int x = 100; x >= 1; x--) { + int res = 0; + int new_idxA = idxA, new_idxB = idxB; + for (int i = idxA; i < N; i++) if (A[i] == x) { res++; new_idxA = i + 1; break; } + for (int i = idxB; i < M; i++) if (B[i] == x) { res++; new_idxB = i + 1; break; } + if (res == 2) { + idxA = new_idxA, idxB = new_idxB; + R.push_back(x); + suc = 1; + break; + } + } + if (!suc) break; + } + cout << R.size() << '\n'; + for (int i : R) cout << i << ' '; + +} + +```