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 itertools import permutations
2+
3+
4+ def solution (numbers ):
5+ numberSet = set ()
6+
7+ for i in range (1 , len (numbers ) + 1 ):
8+ for p in permutations (numbers , i ):
9+ num = int ('' .join (p ))
10+ numberSet .add (num )
11+
12+ count = 0
13+
14+ for num in numberSet :
15+ if num < 2 :
16+ continue
17+ isPrime = True
18+
19+ for i in range (2 , int (num ** 0.5 ) + 1 ):
20+ if num % i == 0 :
21+ isPrime = False
22+ break
23+
24+ if isPrime :
25+ count += 1
26+
27+ return count
Original file line number Diff line number Diff line change 1+ def solution (n , info ):
2+ maxDiff = - 1
3+ answer = [- 1 ]
4+
5+ # DFS로 점수 구간을 하나씩 탐색하면서 라이언의 경우를 모두 탐색
6+ def dfs (index , arrowsLeft , ryanShots ):
7+ nonlocal maxDiff , answer
8+
9+ # 모든 구간을 다 고려했을 때
10+ if index == 11 :
11+ if arrowsLeft > 0 :
12+ ryanShots [10 ] += arrowsLeft
13+
14+ ryanScore = 0
15+ apeachScore = 0
16+
17+ # 각 점수 계산
18+ for i in range (11 ):
19+ if info [i ] == 0 and ryanShots [i ] == 0 :
20+ continue
21+ if ryanShots [i ] > info [i ]:
22+ ryanScore += 10 - i
23+ else :
24+ apeachScore += 10 - i
25+
26+ # 라이언이 이긴 경우
27+ if ryanScore > apeachScore :
28+ diff = ryanScore - apeachScore
29+ if diff > maxDiff :
30+ maxDiff = diff
31+ answer = ryanShots [:]
32+ elif diff == maxDiff :
33+ for i in range (10 , - 1 , - 1 ):
34+ if ryanShots [i ] > answer [i ]:
35+ answer = ryanShots [:]
36+ break
37+ elif ryanShots [i ] < answer [i ]:
38+ break
39+
40+ if arrowsLeft > 0 :
41+ ryanShots [10 ] -= arrowsLeft
42+ return
43+
44+ # 현재 점수를 얻기 위해 필요한 화살 수
45+ neededArrows = info [index ] + 1
46+ if neededArrows <= arrowsLeft :
47+ # 이 점수를 가져가는 경우
48+ ryanShots [index ] = neededArrows
49+ dfs (index + 1 , arrowsLeft - neededArrows , ryanShots )
50+ ryanShots [index ] = 0
51+
52+ # 이 점수를 포기하는 경우
53+ dfs (index + 1 , arrowsLeft , ryanShots )
54+
55+ dfs (0 , n , [0 ] * 11 )
56+ return answer
You can’t perform that action at this time.
0 commit comments