結果

問題 No.179 塗り分け
ユーザー ぴろずぴろず
提出日時 2015-03-26 19:22:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 193 ms / 3,000 ms
コード長 1,159 bytes
コンパイル時間 2,583 ms
コンパイル使用メモリ 74,896 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-09-30 20:35:22
合計ジャッジ時間 10,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,744 KB
testcase_01 AC 132 ms
55,508 KB
testcase_02 AC 129 ms
55,684 KB
testcase_03 AC 129 ms
55,612 KB
testcase_04 AC 127 ms
55,400 KB
testcase_05 AC 139 ms
55,580 KB
testcase_06 AC 131 ms
55,576 KB
testcase_07 AC 167 ms
55,420 KB
testcase_08 AC 152 ms
55,688 KB
testcase_09 AC 152 ms
55,856 KB
testcase_10 AC 135 ms
55,876 KB
testcase_11 AC 136 ms
55,852 KB
testcase_12 AC 182 ms
56,236 KB
testcase_13 AC 129 ms
56,008 KB
testcase_14 AC 132 ms
55,560 KB
testcase_15 AC 128 ms
53,584 KB
testcase_16 AC 127 ms
55,584 KB
testcase_17 AC 129 ms
55,580 KB
testcase_18 AC 139 ms
55,624 KB
testcase_19 AC 139 ms
55,716 KB
testcase_20 AC 181 ms
56,464 KB
testcase_21 AC 166 ms
55,992 KB
testcase_22 AC 193 ms
55,704 KB
testcase_23 AC 136 ms
55,364 KB
testcase_24 AC 156 ms
55,960 KB
testcase_25 AC 138 ms
55,932 KB
testcase_26 AC 143 ms
55,616 KB
testcase_27 AC 181 ms
56,068 KB
testcase_28 AC 143 ms
55,424 KB
testcase_29 AC 188 ms
54,768 KB
testcase_30 AC 159 ms
56,376 KB
testcase_31 AC 158 ms
56,276 KB
testcase_32 AC 143 ms
55,920 KB
testcase_33 AC 191 ms
56,236 KB
testcase_34 AC 142 ms
55,720 KB
testcase_35 AC 186 ms
56,344 KB
testcase_36 AC 129 ms
55,692 KB
testcase_37 AC 132 ms
55,584 KB
testcase_38 AC 130 ms
55,760 KB
testcase_39 AC 128 ms
55,832 KB
testcase_40 AC 128 ms
55,712 KB
testcase_41 AC 126 ms
55,668 KB
testcase_42 AC 129 ms
55,856 KB
testcase_43 AC 136 ms
55,748 KB
testcase_44 AC 138 ms
55,740 KB
testcase_45 AC 133 ms
55,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package division;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] map = new char[h][];
		for(int i=0;i<h;i++) {
			map[i] = sc.next().toCharArray();
		}
		System.out.println(solve(h,w,map) ? "YES" : "NO");
	}

	public static boolean solve(int h,int w,char[][] map) {
		boolean[][] painted = new boolean[h][w];
		for(int di=0;di<h;di++) {
			LOOP: for(int dj=-w+1;dj<w;dj++) {
				if (di == 0 && dj <= 0) {
					continue;
				}
				for(int i=0;i<h;i++) {
					Arrays.fill(painted[i], false);
				}
				int count = 0;
				for(int i=0;i<h;i++) {
					for(int j=0;j<w;j++) {
						if (map[i][j] == '#' && !painted[i][j]) {
							int ni = i + di;
							int nj = j + dj;
							if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
								continue LOOP;
							}
							if (map[ni][nj] != '#' || painted[i][j]) {
								continue LOOP;
							}
							painted[i][j] = painted[ni][nj] = true;
							count++;
						}
					}
				}
				if (count >= 1) {
					return true;
				}
			}
		}
		return false;
	}
}
0