๐ฆ ์๊ถ ๋ํ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from itertools import product
def solution(n, info):
MAX = 0
answer = [-1]
# ์ญ๋ฐฉํฅ ์ํ
info.reverse()
# ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ํ
for result in product([True, False], repeat=11):
apeach_sum = sum(info[i] + 1 for i in range(11) if result[i])
# ํ์ด ๊ฐ์๊ฐ ์ผ์นํ ๋๋ง
if apeach_sum <= n:
apeach = sum(i for i in range(11) if not result[i] and info[i])
ryan = sum(i for i in range(11) if result[i])
sub = ryan - apeach
if MAX < sub:
MAX = sub
answer = [info[i]+ 1 if result[i] else 0 for i in range(11)]
# ๋จ์ ํ์ด์ ์ ์ผ ๋ฎ์ ์ ์์ ๋ฃ์
answer[0] += n - apeach_sum
answer.reverse()
return answer
์ ํ์ฑ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
์ฑ์ ์ ์์ํฉ๋๋ค. ์ ํ์ฑ ํ ์คํธ ํ ์คํธ 1 ใ ํต๊ณผ (5.00ms, 10.2MB) ํ ์คํธ 2 ใ ํต๊ณผ (4.42ms, 10.2MB) ํ ์คํธ 3 ใ ํต๊ณผ (4.50ms, 10.4MB) ํ ์คํธ 4 ใ ํต๊ณผ (3.25ms, 10.4MB) ํ ์คํธ 5 ใ ํต๊ณผ (4.74ms, 10.2MB) ํ ์คํธ 6 ใ ํต๊ณผ (8.74ms, 10.3MB) ํ ์คํธ 7 ใ ํต๊ณผ (3.15ms, 10.2MB) ํ ์คํธ 8 ใ ํต๊ณผ (2.56ms, 10.2MB) ํ ์คํธ 9 ใ ํต๊ณผ (3.23ms, 10.2MB) ํ ์คํธ 10 ใ ํต๊ณผ (2.70ms, 10.3MB) ํ ์คํธ 11 ใ ํต๊ณผ (2.81ms, 10.1MB) ํ ์คํธ 12 ใ ํต๊ณผ (3.00ms, 10.3MB) ํ ์คํธ 13 ใ ํต๊ณผ (3.61ms, 10.1MB) ํ ์คํธ 14 ใ ํต๊ณผ (6.26ms, 10.4MB) ํ ์คํธ 15 ใ ํต๊ณผ (4.50ms, 10.2MB) ํ ์คํธ 16 ใ ํต๊ณผ (5.48ms, 10.3MB) ํ ์คํธ 17 ใ ํต๊ณผ (3.25ms, 10.2MB) ํ ์คํธ 18 ใ ํต๊ณผ (2.42ms, 10.4MB) ํ ์คํธ 19 ใ ํต๊ณผ (4.58ms, 10.2MB) ํ ์คํธ 20 ใ ํต๊ณผ (7.69ms, 10.2MB) ํ ์คํธ 21 ใ ํต๊ณผ (4.42ms, 10.3MB) ํ ์คํธ 22 ใ ํต๊ณผ (4.79ms, 10.1MB) ํ ์คํธ 23 ใ ํต๊ณผ (4.13ms, 10.2MB) ํ ์คํธ 24 ใ ํต๊ณผ (9.17ms, 10.4MB) ํ ์คํธ 25 ใ ํต๊ณผ (4.27ms, 10.3MB) ์ฑ์ ๊ฒฐ๊ณผ ์ ํ์ฑ: 100.0 ํฉ๊ณ: 100.0 / 100.0
3. ํด์ค
ํด์ค
product ๋ฅผ ์ด์ฉํ์ฌ ๋ชจ๋ ์กฐ๊ฑด ์ํ
์ด๊ธธ ๋๋ ์ดํผ์น์ ํ์ด ๊ฐ์ + 1 ๊ฐ ๋งํผ ํฉ์ ๊ตฌํ๊ณ
๊ฐ์ง๊ณ ์๋ ํ์ด๋ณด๋ค ์ ์ ๊ฒฝ์ฐ์๋ง ํฉ๊ณ๋ฅผ ๋น๊ต
๋น๊ตํ ํฉ๊ณ๊ฐ ์ต๋๊ฐ์ผ ๊ฒฝ์ฐ ๋ฐฐ์ด์ ๋ฐ์
๋จ ๋ง์ง๋ง์ ๋จ์ ํ์ด์ ๋ชจ๋ ์ ์ผ ์ ์ ์ ์(0์ )์ ๋ฐ์์์ผ์ผ ํจ
This post is licensed under CC BY 4.0 by the author.