結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-06 20:32:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,382 bytes |
| コンパイル時間 | 594 ms |
| コンパイル使用メモリ | 62,712 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:57:58 |
| 合計ジャッジ時間 | 1,646 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <cstring>
using namespace std;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, -1, 0, 1};
int H, W;
string mat[111];
char at(int y, int x){
if(y < 0 || y >= H || x < 0 || x >= W)return '#';
return mat[y][x];
}
bool used[111][111];
bool check(int sy, int sx, int rest, int y, int x, int d){
if(used[y][x]){
if(y == sy && x == sx && rest == 0){
return true;
} else {
return false;
}
}
used[y][x] = true;
for(int i=0;i<2;i++){
int ny = y + dy[d];
int nx = x + dx[d];
if(at(ny, nx) == '.'){
return check(sy, sx, rest - 1, ny, nx, d);
}
d = (d + 1) % 4;
}
return false;
}
string solve(){
int dot = 0;
for(int y=0;y<H;y++)for(int x=0;x<W;x++)if(mat[y][x] == '.')++dot;
int max_dot = H * 2 + W * 2 - 4;
if(dot > max_dot)return "NO";
for(int sy=0;sy<H;sy++)for(int sx=0;sx<W;sx++)if(mat[sy][sx] == '.'){
for(int d=0;d<4;d++){
memset(used, false, sizeof(used));
if(check(sy, sx, dot, sy, sx, d))return "YES";
}
}
return "NO";
}
int main(){
cin >> H >> W;
for(int i=0;i<H;i++)cin >> mat[i];
cout << solve() << endl;
return 0;
}