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 ().split ()))
6+ print (bfs (N , M , a ))
7+
8+ def bfs (N , M , a ):
9+ queue = deque ()
10+
11+ # 시작위치 0, 눈덩이 크기 1, 시간 0초
12+ queue .append ((- 1 , 1 , 0 ))
13+ maxSize = 1
14+
15+ while queue :
16+ location , size , time = queue .popleft ()
17+
18+ # 시간 초과 or 마지막 칸 도달
19+ if time == M or location == N - 1 :
20+ maxSize = max (maxSize , size )
21+ continue
22+
23+ # 눈동이를 한 칸 이동시킬 경우
24+ nextLoc1 = location + 1
25+ if nextLoc1 < N :
26+ nextSize1 = size + a [nextLoc1 ]
27+ queue .append ((nextLoc1 , nextSize1 , time + 1 ))
28+
29+ # 눈덩이를 두 칸 이동시킬 경우
30+ nextLoc2 = location + 2
31+ if nextLoc2 < N :
32+ nextSize2 = size // 2 + a [nextLoc2 ]
33+ queue .append ((nextLoc2 , nextSize2 , time + 1 ))
34+
35+
36+ return maxSize
37+
38+ if __name__ == '__main__' :
39+ main ()
Original file line number Diff line number Diff line change 1+ from itertools import permutations
2+
3+ def main ():
4+ x = str (input ().strip ())
5+
6+ # 모든 순열 생성
7+ perm = set (permutations (x ))
8+
9+ # 가능한 후보 중 x보다 큰 수
10+ candidates = []
11+ for p in perm :
12+ numStr = '' .join (p )
13+ num = int (numStr )
14+ if num > int (x ):
15+ candidates .append (num )
16+
17+ if candidates :
18+ print (min (candidates ))
19+ else :
20+ print (0 )
21+
22+ if __name__ == "__main__" :
23+ main ()
Original file line number Diff line number Diff line change 1+ def solution (prices ):
2+ answer = [0 ] * len (prices )
3+
4+ stack = []
5+
6+ for i , price in enumerate (prices ):
7+ # 가격이 떨어지는 순간을 찾고 그 때까지의 시간을 계산
8+ while stack and prices [stack [- 1 ]] > price :
9+ j = stack .pop ()
10+ answer [j ] = i - j
11+ stack .append (i )
12+
13+ # for문이 끝난 후 떨어지지 않은 가격
14+ while stack :
15+ j = stack .pop ()
16+ answer [j ] = len (prices ) - (j + 1 )
17+
18+ return answer
You can’t perform that action at this time.
0 commit comments