Skip to content

Commit d9af063

Browse files
committed
[20251023] BOJ / G4 / 가르침 / 김민진
1 parent c4935e2 commit d9af063

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_1062_가르침 {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static StringTokenizer st;
10+
11+
private static int N, K, ans;
12+
private static String[] words;
13+
private static boolean[] alpha;
14+
15+
public static void main(String[] args) throws IOException {
16+
init();
17+
sol(0, 0);
18+
print(ans);
19+
}
20+
21+
private static void init() throws IOException {
22+
st = new StringTokenizer(br.readLine());
23+
N = Integer.parseInt(st.nextToken());
24+
K = Integer.parseInt(st.nextToken());
25+
ans = 0;
26+
27+
words = new String[N];
28+
for (int i = 0; i < N; i++) {
29+
words[i] = br.readLine();
30+
31+
words[i] = words[i].replace("anta", "");
32+
words[i] = words[i].replace("tica", "");
33+
}
34+
35+
if (K < 5) {
36+
print(0);
37+
System.exit(0);
38+
} else if (K >= 26) {
39+
print(N);
40+
System.exit(0);
41+
}
42+
K -= 5;
43+
44+
alpha = new boolean[26];
45+
alpha[0] = true;
46+
alpha['n' - 'a'] = true;
47+
alpha['t' - 'a'] = true;
48+
alpha['i' - 'a'] = true;
49+
alpha['c' - 'a'] = true;
50+
}
51+
52+
private static void sol(int depth, int start) {
53+
if (depth == K) {
54+
countAlpha();
55+
return;
56+
}
57+
58+
for (int i = start; i < 26; i++) {
59+
if (alpha[i]) continue;
60+
61+
alpha[i] = true;
62+
sol(depth + 1, i);
63+
alpha[i] = false;
64+
}
65+
}
66+
67+
private static void countAlpha() {
68+
int cnt = 0;
69+
boolean flag;
70+
for (String word : words) {
71+
flag = true;
72+
for (int i = 0; i < word.length(); i++) {
73+
if (!alpha[word.charAt(i) - 'a']) {
74+
flag = false;
75+
break;
76+
}
77+
}
78+
cnt += flag ? 1 : 0;
79+
}
80+
ans = Math.max(ans, cnt);
81+
}
82+
83+
private static void print(int i) throws IOException {
84+
bw.write(i + "");
85+
bw.flush();
86+
bw.close();
87+
br.close();
88+
}
89+
90+
}
91+
```

0 commit comments

Comments
 (0)