結果

問題 No.179 塗り分け
ユーザー kenkooookenkoooo
提出日時 2015-04-18 00:56:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 281 ms / 3,000 ms
コード長 1,372 bytes
コンパイル時間 3,867 ms
コンパイル使用メモリ 74,224 KB
実行使用メモリ 59,144 KB
最終ジャッジ日時 2023-09-30 20:40:29
合計ジャッジ時間 12,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,560 KB
testcase_01 AC 125 ms
55,904 KB
testcase_02 AC 123 ms
55,668 KB
testcase_03 AC 124 ms
55,680 KB
testcase_04 AC 124 ms
55,888 KB
testcase_05 AC 127 ms
56,272 KB
testcase_06 AC 150 ms
56,408 KB
testcase_07 AC 132 ms
55,748 KB
testcase_08 AC 231 ms
58,468 KB
testcase_09 AC 256 ms
58,600 KB
testcase_10 AC 203 ms
58,740 KB
testcase_11 AC 202 ms
58,524 KB
testcase_12 AC 281 ms
58,684 KB
testcase_13 AC 127 ms
55,952 KB
testcase_14 AC 129 ms
55,860 KB
testcase_15 AC 125 ms
56,180 KB
testcase_16 AC 127 ms
56,304 KB
testcase_17 AC 123 ms
56,104 KB
testcase_18 AC 215 ms
59,056 KB
testcase_19 AC 222 ms
58,736 KB
testcase_20 AC 130 ms
55,748 KB
testcase_21 AC 129 ms
55,840 KB
testcase_22 AC 234 ms
58,912 KB
testcase_23 AC 227 ms
58,596 KB
testcase_24 AC 211 ms
58,880 KB
testcase_25 AC 186 ms
58,788 KB
testcase_26 AC 249 ms
58,736 KB
testcase_27 AC 265 ms
58,796 KB
testcase_28 AC 232 ms
58,260 KB
testcase_29 AC 270 ms
58,848 KB
testcase_30 AC 246 ms
58,640 KB
testcase_31 AC 278 ms
58,428 KB
testcase_32 AC 233 ms
59,012 KB
testcase_33 AC 275 ms
58,964 KB
testcase_34 AC 232 ms
59,144 KB
testcase_35 AC 273 ms
58,672 KB
testcase_36 AC 124 ms
55,944 KB
testcase_37 AC 125 ms
55,804 KB
testcase_38 AC 122 ms
55,992 KB
testcase_39 AC 124 ms
55,628 KB
testcase_40 AC 125 ms
55,816 KB
testcase_41 AC 124 ms
56,016 KB
testcase_42 AC 125 ms
55,844 KB
testcase_43 AC 164 ms
58,188 KB
testcase_44 AC 180 ms
58,052 KB
testcase_45 AC 144 ms
55,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] map = new char[H][];
		for (int i = 0; i < map.length; i++) {
			map[i] = sc.next().toCharArray();
		}

		int cnt = 0;
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				if (map[i][j] == '#') {
					cnt++;
				}
			}
		}
		if (cnt % 2 == 1 || cnt == 0) {
			System.out.println("NO");
			return;
		}

		for (int x = 1 - H; x < H; x++) {
			for (int y = 1 - W; y < W; y++) {
				if (x == 0 && y == 0) {
					continue;
				}
				if (check(x, y, map)) {
					System.out.println("YES");
					return;
				}
			}
		}
		System.out.println("NO");

	}

	static boolean check(int x, int y, char[][] origin) {
		char[][] map = new char[origin.length][origin[0].length];
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				map[i][j] = origin[i][j];
			}
		}

		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				int h = i + x;
				int w = j + y;
				if (map[i][j] == '#') {
					if (h >= map.length || w >= map[i].length || h < 0 || w < 0 || map[h][w] != '#') {
						return false;
					}
					map[i][j] = '.';
					map[h][w] = '.';
				}
			}
		}
		return true;
	}
}
0