結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-05 01:13:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 639 ms / 5,000 ms |
| コード長 | 1,324 bytes |
| コンパイル時間 | 1,401 ms |
| コンパイル使用メモリ | 164,244 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:57:20 |
| 合計ジャッジ時間 | 3,276 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘bool check(int, int, int)’:
main.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
31 | }
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
int H,W,c;
vector<string> m;
const int dir[][2] = {{1,0},{0,-1},{-1,0},{0,1}};
bool check(int cx, int cy, int cd){
int x = cx, y = cy, d = cd;
vector<string> k = m;
int cnt = 0;
while(cnt < c){
int mx = x + dir[d][0];
int my = y + dir[d][1];
if(mx < 0 || my < 0 || mx >= W || my >= H || k[my][mx] == '#'){
d = (d+1)%4;
mx = x + dir[d][0];
my = y + dir[d][1];
if(mx < 0 || my < 0 || mx >= W || my >= H || k[my][mx] == '#'){
return false;
}
}
k[my][mx] = '#';
cnt++;
if(mx == cx && my == cy){
return (c == cnt);
}
x = mx, y = my;
}
}
int main(){
cin >> H >> W;
REP(i,H){
string s;
cin >> s;
if(s.size() != W) throw;
m.push_back(s);
REP(x,W) if(s[x] == '.') c++;
}
if(c == 1) throw;
REP(y,H) REP(x,W){
if(m[y][x] != '.') continue;
REP(d,4){
if(check(x,y,d)){
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}