05-21 07:17
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Mac
- Unity
- preprocessing
- python
- Entity Set
- External Scheme
- 자바
- selenium
- Entity
- Reference Type
- Physical Scheme
- Polymolphism
- Java
- literal
- 리눅스 마스터 1급
- Binary Search
- spring
- Class
- 백준
- dbms
- 셀레니움
- Operator
- descriptive statistics
- Inheritance
- systemd
- OOP
- X윈도우
- X.org
- BFS
- 리눅스
Archives
- Today
- Total
Byeol Lo
N25682 - 체스판 다시 칠하기 2 본문
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;
public class Main {
static final BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
public static void main(String[] args) throws IOException {
String tmp;
st = new StringTokenizer(BR.readLine());
int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());
int paint1 = 4000000, paint2 = 4000000;
int[][] case1 = new int[n+1][m+1], case2 = new int[n+1][m+1];
boolean[][] base = new boolean[2][2];
base[0] = new boolean[] {true, false};
base[1] = new boolean[] {false, true};
for (int i = 0; i < n; i++) {
tmp = BR.readLine();
for (int j = 0; j < m; j++) {
case1[i+1][j+1] = case1[i+1][j] + case1[i][j+1] - case1[i][j] +
(tmp.charAt(j) == 'B' ^ base[i % 2][j % 2] ? 1:0);
case2[i+1][j+1] = case2[i+1][j] + case2[i][j+1] - case2[i][j] +
(tmp.charAt(j) == 'W' ^ base[i % 2][j % 2] ? 1:0);
}
}
for (int i = 0; i < n-k+1; i++) {
for (int j = 0; j < m-k+1; j++) {
paint1 = Math.min(paint1, case1[i+k][j+k] - case1[i][j+k] - case1[i+k][j] + case1[i][j]);
paint2 = Math.min(paint2, case2[i+k][j+k] - case2[i][j+k] - case2[i+k][j] + case2[i][j]);
}
}
System.out.println(Math.min(paint1, paint2));
}
}
'Algorithm > Accumulated Sum' 카테고리의 다른 글
N11660 - 구간 합 구하기 5 (1) | 2024.02.13 |
---|---|
N10986 - 나머지 합 (0) | 2024.02.13 |
Comments