File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments