結果

問題 No.86 TVザッピング(2)
ユーザー cielciel
提出日時 2015-04-24 17:11:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,424 ms / 5,000 ms
コード長 752 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 60,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 15:01:10
合計ジャッジ時間 4,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 1,424 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 965 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
typedef struct{
	int x;
	int y;
}dir;
const dir D[]={
	{0,-1},
	{-1,0},
	{0,1},
	{1,0},
};
int main(){
	int H,W,path=0;
	cin>>H>>W;
	vector<string>v(H);
	for(int i=0;i<H;i++){
		cin>>v[i];
		for(int j=0;j<W;j++)path+=v[i][j]=='.';
	}
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(v[i][j]=='.'){
		for(int _d=0;_d<4;_d++){
			int x=j,y=i,p=0;
			for(int d=_d,fail=0;fail<2&&p<path;){
				int nx=x+D[d].x,ny=y+D[d].y;
				if(0<=nx&&nx<W && 0<=ny&&ny<H && v[ny][nx]=='.'){
					x=nx,y=ny;
					fail=0,p++;
					if(x==j&&y==i)break;
				}else{
					fail++,d=(d+1)%4;
				}
			}
			if(p==path&&x==j&&y==i){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
}
0