Skip to content

Commit ef7a0c0

Browse files
author
hangyeol
committed
98차 1번 문제 풀이
1 parent 3d10b02 commit ef7a0c0

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

live9/test98/문제1/백한결.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from collections import deque
2+
3+
def main():
4+
N, M = map(int, input().split())
5+
a = list(map(int, input().strip().split()))[:N]
6+
7+
print(bfs(N, M, a))
8+
9+
10+
def bfs(N, M, a):
11+
queue = deque()
12+
13+
# 시작위치 0, 눈덩이 크기 1, 시간 0초
14+
queue.append((0, 1, 0))
15+
16+
visited = set()
17+
visited.add((0, 1, 0))
18+
19+
maxSize = 1
20+
21+
while queue:
22+
location, size, time = queue.popleft()
23+
24+
maxSize = max(maxSize, size)
25+
26+
if time == M:
27+
continue
28+
29+
# 눈동이를 한 칸 이동시킬 경우
30+
nextLocation = location + 1
31+
if nextLocation < N:
32+
plusSize = size + a[nextLocation]
33+
current = (nextLocation, plusSize, time+1)
34+
if current not in visited:
35+
visited.add(current)
36+
queue.append(current)
37+
38+
# 눈덩이를 두 칸 이동시킬 경우
39+
nextLocation = location + 2
40+
if nextLocation < N:
41+
plusSize = size // 2 + a[nextLocation]
42+
current = (nextLocation, plusSize, time+1)
43+
if current not in visited:
44+
visited.add(current)
45+
queue.append(current)
46+
47+
return maxSize
48+
49+
50+
if __name__ == '__main__':
51+
main()

0 commit comments

Comments
 (0)