러시아 국기 같은 깃발_4613
Updated:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t = 0;t< T;t++) {
int N = sc.nextInt();
int M = sc.nextInt();
char[][] arr = new char[N][M];
for(int i = 0;i< N; i++) {
String s = sc.next();
for(int j = 0;j< M; j++) {
arr[i][j] = s.charAt(j);
}
}
int Min = Integer.MAX_VALUE;
for(int i = 1;i<N-1;i++) {
for(int j = i+1;j<N;j++){
int Sum = 0;
for(int w = 0;w<i;w++)
for(int k = 0;k<M;k++)
if(arr[w][k]!='W')
Sum++;
for(int b = i;b<j;b++)
for(int k = 0;k<M;k++)
if(arr[b][k]!='B')
Sum++;
for(int r = j;r<N;r++)
for(int k = 0;k<M;k++)
if(arr[r][k]!='R')
Sum++;
if(Min > Sum)
Min = Sum;
}
}
System.out.println("#" + (t + 1) + " " + Min);
}
}
}
Leave a comment