結果

問題 No.179 塗り分け
ユーザー GrenacheGrenache
提出日時 2015-07-02 12:31:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 278 ms / 3,000 ms
コード長 1,740 bytes
コンパイル時間 3,273 ms
コンパイル使用メモリ 75,028 KB
実行使用メモリ 58,988 KB
最終ジャッジ日時 2023-09-30 20:43:25
合計ジャッジ時間 12,415 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,476 KB
testcase_01 AC 124 ms
55,888 KB
testcase_02 AC 125 ms
55,792 KB
testcase_03 AC 125 ms
56,084 KB
testcase_04 AC 125 ms
55,896 KB
testcase_05 AC 129 ms
55,664 KB
testcase_06 AC 145 ms
55,744 KB
testcase_07 AC 136 ms
55,700 KB
testcase_08 AC 133 ms
55,724 KB
testcase_09 AC 145 ms
56,032 KB
testcase_10 AC 189 ms
58,124 KB
testcase_11 AC 186 ms
58,580 KB
testcase_12 AC 278 ms
58,292 KB
testcase_13 AC 126 ms
55,636 KB
testcase_14 AC 130 ms
55,828 KB
testcase_15 AC 124 ms
56,228 KB
testcase_16 AC 125 ms
55,848 KB
testcase_17 AC 126 ms
56,360 KB
testcase_18 AC 221 ms
58,516 KB
testcase_19 AC 194 ms
58,024 KB
testcase_20 AC 132 ms
56,340 KB
testcase_21 AC 134 ms
55,924 KB
testcase_22 AC 277 ms
58,412 KB
testcase_23 AC 176 ms
58,280 KB
testcase_24 AC 240 ms
58,092 KB
testcase_25 AC 195 ms
58,080 KB
testcase_26 AC 170 ms
58,092 KB
testcase_27 AC 235 ms
58,404 KB
testcase_28 AC 159 ms
57,996 KB
testcase_29 AC 234 ms
58,932 KB
testcase_30 AC 162 ms
58,644 KB
testcase_31 AC 197 ms
58,528 KB
testcase_32 AC 201 ms
58,556 KB
testcase_33 AC 217 ms
58,988 KB
testcase_34 AC 169 ms
57,832 KB
testcase_35 AC 202 ms
58,412 KB
testcase_36 AC 126 ms
56,044 KB
testcase_37 AC 125 ms
55,784 KB
testcase_38 AC 125 ms
56,192 KB
testcase_39 AC 124 ms
56,348 KB
testcase_40 AC 126 ms
55,900 KB
testcase_41 AC 124 ms
55,912 KB
testcase_42 AC 123 ms
56,040 KB
testcase_43 AC 150 ms
58,604 KB
testcase_44 AC 166 ms
58,480 KB
testcase_45 AC 128 ms
55,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder179 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();

        char[][] s = new char[h][];
        int black = 0;
        for (int i = 0; i < h; i++) {
        	s[i] = sc.next().toCharArray();
        	for (int j = 0; j < s[i].length; j++) {
        		if (s[i][j] == '#') {
        			black++;
        		}
        	}
        }

        boolean flag = false;
        if (black != 0 && black % 2 == 0) {
        	fin:
        	for (int dx = - w + 1; dx <= w - 1; dx++) {
            	for (int dy = - h + 1; dy <= h - 1; dy++) {
            		int same = 0;
        			boolean[][] used = new boolean[h][w];
            		next:
            		for (int i = 0; i < h; i++) {
            			for (int j = 0; j < w; j++) {
            				if (i + dy >= 0 && i + dy < h && j + dx >= 0 && j + dx < w) {
            					if (s[i][j] == '#' && !used[i][j]) {
            						if (s[i + dy][j + dx] == '#' && !used[i + dy][j + dx]) {
            							used[i][j] = true;
            							used[i + dy][j + dx] = true;
                						same++;
            						} else {
            							same = 0;
            							break next;
            						}
            					}
            				}
            			}
            		}

            		if (same == (black / 2)) {
                		flag = true;
//            			System.out.println(dx + " " + dy);
                		break fin;
            		}
            		
            	}
        	}
        }

        if (flag) {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }

        sc.close();
    }
}
0