結果

問題 No.179 塗り分け
ユーザー GrenacheGrenache
提出日時 2015-07-02 11:43:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,238 bytes
コンパイル時間 2,882 ms
コンパイル使用メモリ 78,060 KB
実行使用メモリ 55,136 KB
最終ジャッジ日時 2024-04-10 12:36:05
合計ジャッジ時間 10,957 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
54,152 KB
testcase_01 AC 105 ms
54,064 KB
testcase_02 AC 105 ms
54,000 KB
testcase_03 AC 94 ms
52,712 KB
testcase_04 AC 108 ms
54,104 KB
testcase_05 AC 113 ms
54,044 KB
testcase_06 WA -
testcase_07 AC 114 ms
53,884 KB
testcase_08 AC 107 ms
52,720 KB
testcase_09 AC 136 ms
54,296 KB
testcase_10 AC 160 ms
54,120 KB
testcase_11 AC 137 ms
54,008 KB
testcase_12 AC 182 ms
53,868 KB
testcase_13 AC 109 ms
53,788 KB
testcase_14 AC 111 ms
54,280 KB
testcase_15 AC 98 ms
53,096 KB
testcase_16 AC 106 ms
53,848 KB
testcase_17 AC 97 ms
52,940 KB
testcase_18 WA -
testcase_19 AC 157 ms
54,452 KB
testcase_20 AC 102 ms
53,000 KB
testcase_21 AC 113 ms
54,180 KB
testcase_22 AC 222 ms
55,004 KB
testcase_23 AC 209 ms
54,576 KB
testcase_24 AC 162 ms
53,528 KB
testcase_25 AC 136 ms
53,292 KB
testcase_26 AC 129 ms
53,336 KB
testcase_27 AC 222 ms
54,340 KB
testcase_28 AC 133 ms
53,340 KB
testcase_29 AC 212 ms
54,672 KB
testcase_30 AC 153 ms
53,952 KB
testcase_31 AC 326 ms
55,068 KB
testcase_32 AC 254 ms
55,000 KB
testcase_33 AC 308 ms
55,048 KB
testcase_34 WA -
testcase_35 AC 260 ms
54,908 KB
testcase_36 AC 109 ms
54,140 KB
testcase_37 AC 96 ms
52,704 KB
testcase_38 AC 104 ms
53,732 KB
testcase_39 AC 105 ms
54,284 KB
testcase_40 AC 99 ms
52,844 KB
testcase_41 AC 107 ms
54,244 KB
testcase_42 AC 113 ms
54,420 KB
testcase_43 AC 130 ms
54,352 KB
testcase_44 AC 166 ms
54,804 KB
testcase_45 AC 109 ms
54,020 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;
//            		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] != s[i + dy][j + dx]) {
//            						break next;
//            					}
            					if (s[i][j] == '#' && s[i + dy][j + dx] == '#') {
            						same++;
            					}
            				}
            			}
            		}
            		
            		if (same == (black / 2)) {
            			boolean[][] used = new boolean[h][w];
                		flag = true;
                		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;
                						} else {
                							flag = false;
                						}
                					}
                				}
                			}
                		}

                		if (flag) {
//                			System.out.println(dx + " " + dy);
                			break fin;
                		}
            		}
            	}
        	}
        }

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

        sc.close();
    }
}
0