-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution_4613_러시아국기같은깃발_유승아.java
54 lines (49 loc) · 1.37 KB
/
Solution_4613_러시아국기같은깃발_유승아.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution_4613_러시아국기같은깃발_유승아 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
for (int testcase = 1; testcase <= T; testcase++) {
// data input
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] color = new int[N][3]; // W, B, R
for (int i = 0; i < N; ++i) {
String s = br.readLine().trim();
for (int j = 0; j < M; j++) {
switch (s.charAt(j)) {
case 'W':
color[i][0]++;
break;
case 'B':
color[i][1]++;
break;
case 'R':
color[i][2]++;
break;
}
}
}
// solve
int res = N * M;
for (int cur = 1; cur <= N - 2; cur++) {
for (int b = 1; b <= N - 1 - cur; b++) {
int sum = 0;
for (int i = 0; i < cur; ++i)
sum += (M - color[i][0]);
for (int i = cur; i < cur + b; ++i)
sum += (M - color[i][1]);
for (int i = cur + b; i < N; ++i)
sum += (M - color[i][2]);
// 결과 갱신
res = Math.min(res, sum);
}
}
// data output
System.out.println("#" + testcase + " " + res);
}
}
}