From b26b237ea5b795c143c965092ff1cbe723f6cb36 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Fri, 12 Jun 2026 20:26:34 +0900 Subject: [PATCH] =?UTF-8?q?12869=20:=20=EB=AE=A4=ED=83=88=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ12869/BOJ12869_V1.cpp | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/week3/BOJ12869/BOJ12869_V1.cpp diff --git a/src/week3/BOJ12869/BOJ12869_V1.cpp b/src/week3/BOJ12869/BOJ12869_V1.cpp new file mode 100644 index 0000000..7a89ffe --- /dev/null +++ b/src/week3/BOJ12869/BOJ12869_V1.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; +int n; +int min_val = INT_MAX; +int health[3]; +int attack[6][3] = { + {9,3,1}, + {9,1,3}, + {3,9,1}, + {3,1,9}, + {1,3,9}, + {1,9,3} +}; +int visited[64][64][64]; +struct st{ + int a,b,c; +}; +queue q; +int bfs(int a, int b, int c) { + visited[a][b][c] = 1; + q.push({a,b,c}); + + while(!q.empty()) { + struct st temp = q.front(); + int a = temp.a; + int b = temp.b; + int c = temp.c; + + q.pop(); + + if (visited[0][0][0]) continue; + for (int i = 0; i < 6; i++) { + int na = max(0, a - attack[i][0]); + int nb = max(0, b - attack[i][1]); + int nc = max(0, c - attack[i][2]); + + if (visited[na][nb][nc]) continue; + q.push({na,nb,nc}); + visited[na][nb][nc] = visited[a][b][c] + 1; + } + } + + return visited[0][0][0] - 1; +} +int main() { + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> health[i]; + } + + cout << bfs(health[0], health[1], health[2]); + + return 0; +} \ No newline at end of file