結果

問題 No.86 TVザッピング(2)
ユーザー リチウムリチウム
提出日時 2014-12-05 06:10:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 629 ms / 5,000 ms
コード長 2,521 bytes
コンパイル時間 2,954 ms
コンパイル使用メモリ 74,472 KB
実行使用メモリ 61,488 KB
最終ジャッジ日時 2023-08-26 14:58:31
合計ジャッジ時間 9,186 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,844 KB
testcase_01 AC 108 ms
55,988 KB
testcase_02 AC 106 ms
56,032 KB
testcase_03 AC 107 ms
55,992 KB
testcase_04 AC 110 ms
56,220 KB
testcase_05 AC 109 ms
56,340 KB
testcase_06 AC 110 ms
55,864 KB
testcase_07 AC 109 ms
56,340 KB
testcase_08 AC 148 ms
56,004 KB
testcase_09 AC 354 ms
61,076 KB
testcase_10 AC 143 ms
56,120 KB
testcase_11 AC 113 ms
55,832 KB
testcase_12 AC 111 ms
56,204 KB
testcase_13 AC 109 ms
55,708 KB
testcase_14 AC 175 ms
59,852 KB
testcase_15 AC 224 ms
60,984 KB
testcase_16 AC 215 ms
61,032 KB
testcase_17 AC 117 ms
56,320 KB
testcase_18 AC 114 ms
55,816 KB
testcase_19 AC 112 ms
56,236 KB
testcase_20 AC 109 ms
56,052 KB
testcase_21 AC 629 ms
61,488 KB
testcase_22 AC 113 ms
55,748 KB
testcase_23 AC 189 ms
59,868 KB
testcase_24 AC 119 ms
56,224 KB
testcase_25 AC 114 ms
56,156 KB
testcase_26 AC 112 ms
56,276 KB
testcase_27 AC 115 ms
56,036 KB
testcase_28 AC 112 ms
55,936 KB
testcase_29 AC 155 ms
57,372 KB
testcase_30 AC 107 ms
56,044 KB
testcase_31 AC 112 ms
55,812 KB
testcase_32 AC 117 ms
56,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.Math.*;
 
public class ppp {
		
  public static void main(String[] args) {
	  Scanner sc=new Scanner(System.in);
	  int n=sc.nextInt();
	  int m=sc.nextInt();
	  boolean ue[][]=new boolean[n][m];
	  boolean sita[][]=new boolean[n][m];
	  boolean hidari[][]=new boolean[n][m];
	  boolean migi[][]=new boolean[n][m];
	  boolean map[][]=new boolean[n][m];
	  int sum=0;
	  for(int i=0;i<n;i++){
		  String s=sc.next();
		  for(int j=0;j<m;j++){
			  if(s.substring(j,j+1).equals(".")){
				  map[i][j]=true;
				  sum++;
			  }
		  }
	  }
	  for(int i=1;i<n-1;i++){
		  for(int j=1;j<m-1;j++){
			  if(map[i-1][j-1]&map[i-1][j]&map[i-1][j+1]&map[i][j-1]&map[i][j]&map[i][j+1]&map[i+1][j-1]&map[i+1][j]&map[i+1][j+1]){
				  System.out.println("NO");
				  return;
			  }
		  }
	  }
	 
	  for(int i=1;i<n;i++){
		  for(int j=0;j<m;j++){
			  ue[i][j]=map[i-1][j]|ue[i-1][j];
			  sita[n-1-i][j]=map[n-i][j]|sita[n-i][j];
		  }
	  }
	  for(int i=1;i<m;i++){
		  for(int j=0;j<n;j++){
			  hidari[j][i]=map[j][i-1]|hidari[j][i-1];
			  migi[j][m-1-i]=map[j][m-i]|migi[j][m-i];
		  }
		  
	  }
	  
	  int dx[]={0,-1,0,1};
	  int dy[]={-1,0,1,0};
	  for(int i=0;i<n;i++){
		  for(int j=0;j<m;j++){
			  for(int k=0;k<4;k++){
				  if(!map[i][j])continue;
				  int Y=i+dy[k];
				  int X=j+dx[k];
				  if(!(0<=X && X<m && 0<=Y && Y<n))continue;
				  if(!map[i+dy[k]][j+dx[k]])continue;
				  int nowx=j;
				  int nowy=i;
				  int d=k;
				  int now=sum;
				  boolean mapc[][]=new boolean[n][m];
				  for(int p=0;p<n;p++){
					  for(int w=0;w<m;w++){
						  mapc[p][w]=map[p][w];
					  }
				  }
				  while(now>0){
					  int y=nowy+dy[d%4];
					  int x=nowx+dx[d%4];
					  if(!(0<=x && x<m && 0<=y && y<n) ||!mapc[nowy+dy[d%4]][nowx+dx[d%4]])d++;
					  y=nowy+dy[d%4];
					  x=nowx+dx[d%4];
					  if(!(0<=x && x<m && 0<=y && y<n))break;
					  nowy+=dy[d%4];
					  nowx+=dx[d%4];
					  if(!mapc[nowy][nowx])break;
					  mapc[nowy][nowx]=false;					  
					  now--;
					  switch(d%4){
					  case 0:
						  if(migi[nowy][nowx])break;
					  
					  case 1:
						  if(ue[nowy][nowx])break;
					  
					  case 2:
						  if(hidari[nowy][nowx])break;
			
					  case 3:
						  if(sita[nowy][nowx])break;
				  }
				  }
				  if(nowy==i && nowx==j && now==0){
					  System.out.println("YES");
					  return;
			  }
		  }
	  }
	  }
	  System.out.println("NO");
  }}
0