728x90
https://programmers.co.kr/learn/courses/30/lessons/60062
// 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import java.util.*;
class Solution {
static final int INF = Integer.MAX_VALUE;
int MinCnt;
int N;
int[] Weak;
int[] Dist;
// 메서드 : 친구명수(x), 취약점 시작할 위치(idx), 각 취약점의 방문여부(visited)
void getResult(int x, int idx, int visited) {
if(x > Dist.length) return;
if(x >= MinCnt) return;
for(int i=0; i<Weak.length; ++i) {
int nextPos = (idx + i) % Weak.length;
int diff = Weak[nextPos] - Weak[idx];
if(nextPos < idx) diff += N;
if(diff > Dist[Dist.length - x]) break;
visited |= 1 << nextPos;
}
if(visited == (1 << Weak.length) - 1) {
MinCnt = x;
return;
}
for(int i=0; i<Weak.length; ++i) {
if((visited & (1 << i)) != 0) continue;
getResult(x + 1, i, visited);
}
}
public int solution(int n, int[] weak, int[] dist) {
Arrays.sort(dist);
N = n;
Weak = weak;
Dist = dist;
MinCnt = INF;
for(int i=0; i<Weak.length; ++i) {
getResult(1, i, 0);
}
if(MinCnt == INF) return -1;
return MinCnt;
}
}
|
cs |
반응형
'CS > 알고리즘_KAKAO BLIND RECRUITMENT' 카테고리의 다른 글
2020 KAKAO BLIND RECRUITMENT : 가사 검색 (0) | 2021.10.18 |
---|---|
2018 KAKAO BLIND RECRUITMENT : [1차] 캐시 (0) | 2021.10.15 |
2021 KAKAO BLIND RECRUITMENT : 카드 짝 맞추기(리뷰 필요) (0) | 2021.10.13 |
2018 KAKAO BLIND RECRUITMENT : [3차] 압축 (0) | 2021.10.12 |
2018 KAKAO BLIND RECRUITMENT : [3차] 자동완성 (0) | 2021.10.11 |