File tree Expand file tree Collapse file tree 2 files changed +19
-33
lines changed
Expand file tree Collapse file tree 2 files changed +19
-33
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 17776 KB, 시간: 164 ms
7+ 메모리: 17508 KB, 시간: 160 ms
88
99### 분류
1010
1111분할 정복, 재귀
1212
1313### 제출 일자
1414
15- 2025년 7월 10일 17:33:01
15+ 2025년 7월 10일 17:40:42
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 22// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
33
44import java .io .*;
5- import java .util .*;
65
76public class Main {
87 static int [][] square ;
9- static int N , white =0 , blue =0 ;
8+ static int white =0 , blue =0 ;
109
1110
1211 public static void main (String [] args ) throws IOException {
1312 BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
14- N = Integer .parseInt (br .readLine ());
13+ int N = Integer .parseInt (br .readLine ());
1514 square = new int [N ][N ];
1615
1716 // 초기 2차원 배열 세팅
@@ -29,45 +28,32 @@ public static void main(String[] args) throws IOException{
2928
3029 public static void check (int x , int y , int n ){
3130
32- boolean isWhite = true ;
33- boolean isBlue = true ;
31+ boolean isSame = true ;
32+ int color = square [ x ][ y ]; // 시작 원소를 기준점으로 잡는다
3433
35- // 전체 색칠되있거나 안칠해져있는지 확인
36- loop1 :
3734 for (int i =x ; i <x +n ; i ++){
3835 for (int j =y ; j <y +n ; j ++){
39- if (square [i ][j ] != 0 ){
40- isWhite =false ;
41- break loop1 ;
36+ if (square [i ][j ] != color ){
37+ isSame =false ;
38+ break ;
4239 }
4340 }
4441 }
4542
46- if (isWhite == true ) {
47- white ++;
48- return ;
49- }
50-
51- loop2 :
52- for (int i =x ; i <x +n ; i ++){
53- for (int j =y ; j <y +n ; j ++){
54- if (square [i ][j ] != 1 ){
55- isBlue =false ;
56- break loop2 ;
57- }
43+ if (isSame == true ){
44+ if (color == 1 ){
45+ blue ++;
46+ }else {
47+ white ++;
5848 }
59- }
60-
61- if (isBlue ==true ){
62- blue ++;
6349 return ;
6450 }
6551
66- int length = n / 2 ;
52+ n /= 2 ;
6753
68- check (x , y , length );
69- check (x +length , y , length );
70- check (x , y +length , length );
71- check (x +length , y +length , length );
54+ check (x , y , n );
55+ check (x +n , y , n );
56+ check (x , y +n , n );
57+ check (x +n , y +n , n );
7258 }
7359}
You can’t perform that action at this time.
0 commit comments