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+ def solution (k , dungeons ):
2+ dungeons = [d for d in dungeons if k >= d [0 ]]
3+
4+ def calculate_fatigue (dungeons , tmp , cnt ):
5+ max_cnt = cnt
6+ for r , c in dungeons :
7+ if r <= tmp :
8+ new_dungeons = dungeons [:] # 복사
9+ new_dungeons .remove ([r , c ])
10+ max_cnt = max (max_cnt , calculate_fatigue (new_dungeons , tmp - c , cnt + 1 ))
11+ return max_cnt
12+
13+
14+ return calculate_fatigue (dungeons , k , 0 )
Original file line number Diff line number Diff line change 1+ from collections import *
2+
3+
4+
5+ def solution (n , wires ):
6+
7+ def create_graph (wires ):
8+ graph = [[] for _ in range (n + 1 )]
9+
10+ for v1 , v2 in wires :
11+ graph [v1 ].append (v2 )
12+ graph [v2 ].append (v1 )
13+ return graph
14+
15+ def bfs (graph , x , visited ):
16+ cnt = 1
17+ q = deque ([x ])
18+ visited [x ] = 1
19+ while q :
20+ x = q .popleft ()
21+ for nx in graph [x ]:
22+ if not visited [nx ]:
23+ visited [nx ] = 1
24+ cnt += 1
25+ q .append (nx )
26+ return cnt
27+
28+ answer = float ('inf' )
29+
30+ # 모든 간선 하나씩 끊어보기
31+ for i in range (len (wires )):
32+ tmp = wires [:]
33+ del tmp [i ]
34+ tmp_graph = create_graph (tmp )
35+
36+ visited = [0 ] * (n + 1 )
37+ count = []
38+
39+ for num in range (1 , n + 1 ):
40+ if not visited [num ]:
41+ count .append (bfs (tmp_graph , num , visited ))
42+
43+ diff = abs (count [0 ] - count [1 ])
44+ answer = min (answer , diff )
45+
46+ return answer
Original file line number Diff line number Diff line change 1+ # 처음 푼 풀이
2+ from itertools import *
3+
4+ def solution (brown , yellow ):
5+ answer = []
6+ yellow_list = set ()
7+ if yellow == 1 : yellow_list .add (1 )
8+ for i in range (1 , yellow // 2 + 1 ):
9+ if yellow % i == 0 :
10+ yellow_list .add (i )
11+ yellow_list .add (yellow // i )
12+
13+ for x , y in product (yellow_list , repeat = 2 ):
14+ if x * y == yellow and x >= y :
15+ if x * 2 + y * 2 + 4 == brown :
16+ answer .append (x + 2 )
17+ answer .append (y + 2 )
18+
19+ return answer
20+
21+ # 다른 풀이 보니 중복 순열을 굳이 쓸 필요 없음
22+ def solution (brown , yellow ):
23+ for i in range (1 , int (yellow ** 0.5 ) + 1 ):
24+ if yellow % i == 0 :
25+ if (i + yellow // i ) * 2 == brown - 4 :
26+ return [yellow // i + 2 , i + 2 ]
You can’t perform that action at this time.
0 commit comments