From 47de79c2026c0cb041f213a17b4b9f1c99931e3a Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 25 Feb 2025 17:18:54 +0900 Subject: [PATCH] =?UTF-8?q?[20250225]=20BOJ=20/=20S1=20/=20=EB=8F=8C?= =?UTF-8?q?=EB=8B=A4=EB=A6=AC=20/=20=EA=B6=8C=ED=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \353\217\214\353\213\244\353\246\254.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "khj20006/202502/25 BOJ S1 \353\217\214\353\213\244\353\246\254.md" diff --git "a/khj20006/202502/25 BOJ S1 \353\217\214\353\213\244\353\246\254.md" "b/khj20006/202502/25 BOJ S1 \353\217\214\353\213\244\353\246\254.md" new file mode 100644 index 00000000..c1a45129 --- /dev/null +++ "b/khj20006/202502/25 BOJ S1 \353\217\214\353\213\244\353\246\254.md" @@ -0,0 +1,37 @@ +```cpp + +#include +#include +#include +using namespace std; + +int main() +{ + cin.tie(0)->sync_with_stdio(0); + + int A, B, N, M; + cin >> A >> B >> N >> M; + bitset<100001> v; + queue> Q; + Q.emplace(N, 0); + v[N] = 1; + + int d[6] = { 1,-1,A,-A,B,-B }; + while (!Q.empty()) { + auto[n, t] = Q.front(); + Q.pop(); + if (n == M) return cout << t, 0; + for (int i = 0; i < 6; i++) { + int x = n + d[i]; + if (x < 0 || x > 100000 || v[x]) continue; + v[x] = 1; + Q.emplace(x, t + 1); + } + if (n*A <= 100000 && !v[n*A]) { v[n*A] = 1; Q.emplace(n*A, t + 1); } + if (n*B <= 100000 && !v[n*B]) { v[n*B] = 1; Q.emplace(n*B, t + 1); } + } + + +} + +```