알고리즘
백준 2563 색종이
킨글
2024. 8. 22. 20:35
설명
코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
// 1531
public static void main(String[] args) throws IOException {
process();
}
private static void process() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int loop = Integer.parseInt(br.readLine());
int[][] arr = new int[101][101];
for (int i = 0; i < loop; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int xEnd = Math.min(x + 9, 100);
int yEnd = Math.min(y + 9, 100);
for (int j = y; j <= yEnd; j++) {
for (int k = x; k <= xEnd; k++) {
arr[j][k] = 1;
}
}
}
int cnt = 0;
for (int i = 1; i < 101; i++) {
for (int j = 1; j < 101 ; j++) {
if(arr[i][j] == 1) {
cnt++;
}
}
}
bw.write(cnt + "");
bw.flush();
bw.close();
br.close();
}
}