-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJY_64064.java
More file actions
56 lines (50 loc) · 1.59 KB
/
JY_64064.java
File metadata and controls
56 lines (50 loc) · 1.59 KB
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 JY_64064 {
static Set<Set<String>> uSet;
static Set<String> bSet;
public int solution(String[] user_id, String[] banned_id) {
int answer = 0;
uSet = new HashSet<>();
bSet = new HashSet<>();
dfs(0, user_id, banned_id);
// System.out.println(uSet);
answer = uSet.size();
return answer;
}
public static boolean findId(String u, String b) {
if(u.length() != b.length()) return false;
for(int i=0; i<b.length(); i++) {
if(b.charAt(i) == '*') continue;
if(u.charAt(i) != b.charAt(i)) return false;
}
return true;
}
public static void dfs(int depth, String[] urr, String[] brr) {
if(depth == brr.length) {
boolean isOk = true;
for(Set<String> sub : uSet) {
if(sub.containsAll(bSet)) {
isOk = false;
break;
}
}
if(isOk) {
// copy
Set<String> tmp = new HashSet<>();
for(String s : bSet){
tmp.add(s);
}
uSet.add(tmp);
}
return;
}
for(String s : urr) {
// 현재 제재 아이디 목록에 있지 않고 && 불량 사용자 아이디와 매핑 된다면
if(!bSet.contains(s) && findId(s, brr[depth])) {
bSet.add(s);
dfs(depth+1, urr, brr);
bSet.remove(s);
}
}
}
}