結果

問題 No.179 塗り分け
ユーザー uafr_csuafr_cs
提出日時 2015-08-06 19:12:32
言語 Java19
(openjdk 21)
結果
AC  
実行時間 591 ms / 3,000 ms
コード長 1,522 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 74,392 KB
実行使用メモリ 57,736 KB
最終ジャッジ日時 2023-09-30 20:44:06
合計ジャッジ時間 17,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,004 KB
testcase_01 AC 125 ms
55,748 KB
testcase_02 AC 125 ms
55,872 KB
testcase_03 AC 126 ms
56,120 KB
testcase_04 AC 125 ms
55,844 KB
testcase_05 AC 268 ms
56,388 KB
testcase_06 AC 188 ms
56,592 KB
testcase_07 AC 340 ms
57,296 KB
testcase_08 AC 133 ms
55,904 KB
testcase_09 AC 169 ms
56,676 KB
testcase_10 AC 233 ms
57,736 KB
testcase_11 AC 246 ms
57,180 KB
testcase_12 AC 422 ms
57,308 KB
testcase_13 AC 128 ms
55,932 KB
testcase_14 AC 129 ms
55,876 KB
testcase_15 AC 126 ms
56,588 KB
testcase_16 AC 124 ms
55,984 KB
testcase_17 AC 123 ms
56,208 KB
testcase_18 AC 366 ms
57,564 KB
testcase_19 AC 277 ms
56,744 KB
testcase_20 AC 456 ms
56,880 KB
testcase_21 AC 538 ms
57,448 KB
testcase_22 AC 477 ms
57,192 KB
testcase_23 AC 400 ms
57,416 KB
testcase_24 AC 488 ms
57,228 KB
testcase_25 AC 405 ms
57,344 KB
testcase_26 AC 369 ms
57,440 KB
testcase_27 AC 514 ms
57,584 KB
testcase_28 AC 423 ms
57,148 KB
testcase_29 AC 563 ms
57,428 KB
testcase_30 AC 274 ms
55,244 KB
testcase_31 AC 591 ms
57,344 KB
testcase_32 AC 341 ms
57,496 KB
testcase_33 AC 487 ms
57,356 KB
testcase_34 AC 385 ms
57,436 KB
testcase_35 AC 489 ms
57,352 KB
testcase_36 AC 124 ms
55,840 KB
testcase_37 AC 125 ms
55,956 KB
testcase_38 AC 125 ms
56,296 KB
testcase_39 AC 124 ms
56,084 KB
testcase_40 AC 127 ms
55,956 KB
testcase_41 AC 126 ms
55,728 KB
testcase_42 AC 124 ms
55,976 KB
testcase_43 AC 229 ms
56,308 KB
testcase_44 AC 316 ms
56,616 KB
testcase_45 AC 151 ms
56,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int H = sc.nextInt();
		final int W = sc.nextInt();
		
		boolean[][] fields = new boolean[H][W];
		for(int i = 0; i < H; i++){
			char[] inputs = sc.next().toCharArray();
			for(int j = 0; j < W; j++){
				fields[i][j] = inputs[j] == '#';
			}
		}
		
		boolean[][] checked = new boolean[H][W];
		
		for(int dy = -(H - 1); dy < H; dy++){
			for(int dx = -(W - 1); dx < W; dx++){
				if(dx == 0 && dy == 0){ continue; }
				
				for(int i = 0; i < H; i++){
					for(int j = 0; j < W; j++){
						checked[i][j] = false;
					}
				}
				
				
				for(int y = 0; y < H; y++){
					for(int x = 0; x < W; x++){
						final int nx = x + dx;
						final int ny = y + dy;
						if(nx < 0 || nx >= W || ny < 0 || ny >= H){ continue; }
						
						if(checked[y][x] || checked[ny][nx]){ continue; }
						
						if(fields[y][x] && fields[ny][nx]){
							checked[y][x] = checked[ny][nx] = true;
						}
					}
				}
				
				boolean found = false;
				boolean flg = true;
				for(int i = 0; i < H; i++){
					for(int j = 0; j < W; j++){
						if(fields[i][j]){ found = true; }
						
						if(fields[i][j] && !checked[i][j]){
							flg = false;
						}
					}
				}
				
				if(flg && found){
					System.out.println("YES");
					return;
				}
			}
		}
		
		System.out.println("NO");
	}
	
}
0