From c2395e8dff622043620bb59f1d784800b56bd92b Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 6 Jul 2026 15:32:29 +0900 Subject: [PATCH] =?UTF-8?q?17071=20:=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=205=20resolve/2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ17071/BOJ17071_V3.cpp | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/week3/BOJ17071/BOJ17071_V3.cpp diff --git a/src/week3/BOJ17071/BOJ17071_V3.cpp b/src/week3/BOJ17071/BOJ17071_V3.cpp new file mode 100644 index 0000000..7f0fc0c --- /dev/null +++ b/src/week3/BOJ17071/BOJ17071_V3.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int visited[2][500001]; +int subin, bro; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> subin >> bro; + + queue q; + q.push(subin); + visited[0][subin] = 1; + int t=0; + while(!q.empty()) { + int qsize = q.size(); + while (qsize--) { + subin = q.front(); + q.pop(); + int bro_pos = bro + ((t * (t+1)) / 2); + if (bro_pos > 500000) break; + + if (visited[t%2][bro_pos]) { + cout << t << '\n'; + return 0; + } + for (int next : {subin -1, subin + 1, subin * 2}) { + if (next < 0 || next >500000 || visited[(t+1)%2][next]) continue; + q.push(next); + visited[(t+1)%2][next] = 1; + } + } + t++; + } + + cout << -1 << '\n'; + + return 0; +} \ No newline at end of file