From 27d3ad8c09899111b30ea6c911d9136cf6ce2fd5 Mon Sep 17 00:00:00 2001 From: yeoncheol-kim Date: Thu, 29 May 2025 11:41:06 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C=20Study:=20=EC=96=91=EA=B6=81?= =?UTF-8?q?=EB=8C=80=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...21\352\266\201\353\214\200\355\232\214.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "\354\226\221\352\266\201\353\214\200\355\232\214.py" diff --git "a/\354\226\221\352\266\201\353\214\200\355\232\214.py" "b/\354\226\221\352\266\201\353\214\200\355\232\214.py" new file mode 100644 index 0000000..6bdca22 --- /dev/null +++ "b/\354\226\221\352\266\201\353\214\200\355\232\214.py" @@ -0,0 +1,22 @@ +def solution(n, info): + best = [-1] + max_diff = 0 + def dfs(i, left, shot): + nonlocal best, max_diff + if i == 11: + shot[10] += left + scores = [(10 - j) * (s > a) for j, (s, a) in enumerate(zip(shot, info))] + lion = sum(scores) + apeach = sum(10 - j for j in range(11) if info[j] and shot[j] <= info[j]) + if (diff := lion - apeach) > 0: + if diff > max_diff or (diff == max_diff and shot[::-1] > best[::-1]): + best, max_diff = shot[:], diff + shot[10] -= left + return + for x in (info[i] + 1, 0): + if x <= left: + shot[i] = x + dfs(i + 1, left - x, shot) + shot[i] = 0 + dfs(0, n, [0] * 11) + return best