結果

問題 No.86 TVザッピング(2)
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-19 06:14:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 670 ms / 5,000 ms
コード長 1,482 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 145,048 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 15:02:06
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef long long ll;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<long long,long long> Pii;
typedef vector<Pii> VPii;


int dx[] = {-1,0,+1,0};
int dy[] = {0,+1,0,-1};
char a[128][128];
int dn[128][128];
int H,W;
int valid(int x,int y){
	if( x < 0 || y < 0 || x >= W || y >= H ) return 0;
	if( a[y][x] == '#' ) return 0;
	if( dn[y][x] ) return 0;
	return 1;
}

int main(){
	
	cin >> H >> W;
	int c = 0;
	rep(i,H)rep(j,W) cin >> a[i][j], c += a[i][j] == '.';
	rep(i,H)rep(j,W){
		
		if( valid(j,i) == 0 ) continue;
		rep(d_,4){
			int s = 0;
			int d = d_;
			int x = j;
			int y = i;
			while(1){
				
				
				if( valid(x+dx[d],y+dy[d]) == 0 ){
					//cout << i << " " << j << "|" << y << " " << x << "|" << s << "(" << dx[d_] << ")" << endl;
					if( (x+dx[d] == j && y+dy[d] == i || x+dx[(d+3)%4] == j && y+dy[(d+3)%4] == i)  && s == c ){
						//cout << i << " " << j << "|" << y << " " << x << "|" << d_ << " " << d << endl;
						cout << "YES" << endl;
						return 0;
					}
					break;
				}
				if( dn[y][x] == 0 ){
					s++;
					dn[y][x] = true;
				}
				while( valid(x+dx[d],y+dy[d]) ){
					x += dx[d];
					y += dy[d];
					dn[y][x] = true;
					s ++;
				}
				d = (d+1) % 4;
			}
			memset(dn,0,sizeof(dn));
		}
	}
	cout << "NO" << endl;
}
0