結果

問題 No.179 塗り分け
ユーザー YamaKasaYamaKasa
提出日時 2018-07-26 21:06:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 265 ms / 3,000 ms
コード長 1,235 bytes
コンパイル時間 3,714 ms
コンパイル使用メモリ 73,500 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-09-30 21:02:46
合計ジャッジ時間 12,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,536 KB
testcase_01 AC 123 ms
55,644 KB
testcase_02 AC 122 ms
55,488 KB
testcase_03 AC 121 ms
55,680 KB
testcase_04 AC 122 ms
55,328 KB
testcase_05 AC 182 ms
56,256 KB
testcase_06 AC 145 ms
55,916 KB
testcase_07 AC 265 ms
56,008 KB
testcase_08 AC 151 ms
55,408 KB
testcase_09 AC 157 ms
55,604 KB
testcase_10 AC 149 ms
55,772 KB
testcase_11 AC 147 ms
55,764 KB
testcase_12 AC 150 ms
56,172 KB
testcase_13 AC 121 ms
55,420 KB
testcase_14 AC 126 ms
56,108 KB
testcase_15 AC 120 ms
55,712 KB
testcase_16 AC 119 ms
55,404 KB
testcase_17 AC 119 ms
55,712 KB
testcase_18 AC 149 ms
55,680 KB
testcase_19 AC 148 ms
55,664 KB
testcase_20 AC 151 ms
55,872 KB
testcase_21 AC 165 ms
56,340 KB
testcase_22 AC 194 ms
53,804 KB
testcase_23 AC 148 ms
55,400 KB
testcase_24 AC 155 ms
56,076 KB
testcase_25 AC 165 ms
55,820 KB
testcase_26 AC 149 ms
56,060 KB
testcase_27 AC 152 ms
56,044 KB
testcase_28 AC 148 ms
55,668 KB
testcase_29 AC 152 ms
56,060 KB
testcase_30 AC 152 ms
55,572 KB
testcase_31 AC 153 ms
56,224 KB
testcase_32 AC 150 ms
56,268 KB
testcase_33 AC 152 ms
56,000 KB
testcase_34 AC 149 ms
55,396 KB
testcase_35 AC 152 ms
55,700 KB
testcase_36 AC 120 ms
55,788 KB
testcase_37 AC 120 ms
55,800 KB
testcase_38 AC 120 ms
55,724 KB
testcase_39 AC 120 ms
55,964 KB
testcase_40 AC 121 ms
55,796 KB
testcase_41 AC 121 ms
55,968 KB
testcase_42 AC 119 ms
53,904 KB
testcase_43 AC 147 ms
55,704 KB
testcase_44 AC 172 ms
56,220 KB
testcase_45 AC 125 ms
55,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();
		int W = scan.nextInt();
		char c[][] = new char[H][W];
		for(int i = 0; i < H; i++) {
			String s = scan.next();
			for(int j = 0; j < W; j++) {
				c[i][j] = s.charAt(j);
			}
		}
		scan.close();
		boolean [][]s = new boolean[H][W];
		boolean flag = false;
		for(int dy = -H; dy <= H; dy++) {
			for(int dx = -W; dx <= W; dx++) {
				if(dy == 0 && dx == 0) {
					continue;
				}
				for(int i = 0; i < H; i++) {
					for(int j = 0; j < W; j++) {
						s[i][j] =false;
					}
				}

				for(int k = 0; k < (H - 1) * W + W; k++) {
					int y = k / W;
					int x = k % W;
						if(c[y][x] == '#' && s[y][x] == false) {
							s[y][x] = true;
							if(y + dy < 0 || y + dy >= H || x + dx < 0 || x + dx >= W) {
								flag = false;
								break;
							}

							if(c[y + dy][x + dx] == '#' && s[y + dy][x + dx] == false) {
								s[y + dy][x + dx] = true;
								flag = true;
							}else {
								flag = false;
								break;
							}
						}
					}
					if(flag) {
						System.out.println("YES");
						System.exit(0);
					}
				}

			}
		System.out.println("NO");
	}
}
0