結果

問題 No.86 TVザッピング(2)
ユーザー ぴろずぴろず
提出日時 2014-12-05 00:27:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,696 ms / 5,000 ms
コード長 1,748 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 60,044 KB
最終ジャッジ日時 2023-08-26 14:57:45
合計ジャッジ時間 11,852 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,728 KB
testcase_01 AC 133 ms
56,752 KB
testcase_02 AC 128 ms
56,744 KB
testcase_03 AC 129 ms
56,840 KB
testcase_04 AC 131 ms
56,544 KB
testcase_05 AC 128 ms
56,824 KB
testcase_06 AC 131 ms
57,064 KB
testcase_07 AC 127 ms
56,808 KB
testcase_08 AC 169 ms
56,752 KB
testcase_09 AC 904 ms
59,720 KB
testcase_10 AC 1,696 ms
59,820 KB
testcase_11 AC 138 ms
56,920 KB
testcase_12 AC 134 ms
56,508 KB
testcase_13 AC 133 ms
56,420 KB
testcase_14 AC 200 ms
59,688 KB
testcase_15 AC 231 ms
59,244 KB
testcase_16 AC 222 ms
59,836 KB
testcase_17 AC 132 ms
56,800 KB
testcase_18 AC 137 ms
55,304 KB
testcase_19 AC 139 ms
56,720 KB
testcase_20 AC 136 ms
56,844 KB
testcase_21 AC 1,070 ms
58,012 KB
testcase_22 AC 127 ms
57,020 KB
testcase_23 AC 186 ms
59,804 KB
testcase_24 AC 134 ms
56,748 KB
testcase_25 AC 126 ms
56,752 KB
testcase_26 AC 125 ms
57,092 KB
testcase_27 AC 131 ms
56,740 KB
testcase_28 AC 133 ms
56,440 KB
testcase_29 AC 755 ms
60,044 KB
testcase_30 AC 134 ms
56,852 KB
testcase_31 AC 133 ms
56,568 KB
testcase_32 AC 140 ms
56,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no086;

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

public class Main {
	public static final int[] di = {0,-1,0,1};
	public static final int[] dj = {1,0,-1,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		char[][] map = new char[n+2][];
		int channels = 0;
		for(int i=1;i<=n;i++) {
			map[i] = ("#" + sc.next() + "#").toCharArray() ;
		}
		map[0] = new char[m+2];
		map[n+1] = new char[m+2];
		Arrays.fill(map[0], '#');
		Arrays.fill(map[n+1], '#');
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				if (map[i][j] == '.') {
					channels++;
				}
			}
		}
		for(int si=1;si<=n;si++) {
			for(int sj=1;sj<=m;sj++) {
				if (map[si][sj] == '#') {
					continue;
				}
				for(int sd=0;sd<4;sd++) {
					int i = si;
					int j = sj;
					int dir = sd;
					boolean[][] used = new boolean[n+2][m+2];
					for(int i2=0;i2<=n+1;i2++) {
						for(int j2=0;j2<=m+1;j2++) {
							if (map[i2][j2] == '#') {
								used[i2][j2] = true;
							}
						}
					}
					int count = 0;
					while(true) {
						if (used[i][j]) {
							if (i == si && j == sj && count == channels) {
								System.out.println("YES");
								return;
							}
							break;
						}
						used[i][j] = true;
						count++;
						int ni = i + di[dir];
						int nj = j + dj[dir];
						if (used[ni][nj] && !(ni == si && nj == sj)) {
							int dir2 = (dir+1) % 4;
							if (used[i+di[dir2]][j+dj[dir2]] && !(i+di[dir2] == si && j+dj[dir2] == sj)) {
								break;
							}
							dir = dir2;
						}
						i += di[dir];
						j += dj[dir];
					}
				}
			}
		}
		System.out.println("NO");
	}

}
0