結果
問題 | No.86 TVザッピング(2) |
ユーザー |
|
提出日時 | 2017-01-08 23:00:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,645 bytes |
コンパイル時間 | 792 ms |
コンパイル使用メモリ | 79,044 KB |
実行使用メモリ | 10,532 KB |
最終ジャッジ日時 | 2024-12-17 23:00:40 |
合計ジャッジ時間 | 9,701 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 1 |
ソースコード
#include <iostream>#include <vector>#include <set>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))using namespace std;bool solve(int h, int w, vector<string> const & f) {auto is_on_field = [&](int y, int x) { return 0 <= y and y < h and 0 <= x and x < w; };auto pred = [&](int y, int x) { return is_on_field(y, x) and f[y][x] == '.'; };const int dy[] = { 0, -1, 0, 1 }; // counter-clockwiseconst int dx[] = { 1, 0, -1, 0 };int total = 0; repeat (y,h) repeat (x,w) total += pred(y, x);repeat (y0,h) repeat (x0,w) if (pred(y0, x0)) {repeat (d0,4) {int y = y0;int x = x0;int d = d0;set<pair<int, int> > used;while (true) {if (not used.empty() and y == y0 and x == x0) {if (used.size() == total) return true;break;}int dd = 0;for (; dd < 2; ++ dd) {int nd = (d + dd) % 4;int ny = y + dy[nd];int nx = x + dx[nd];if (pred(ny, nx) and not used.count(make_pair(ny, nx))) {y = ny;x = nx;d = nd;used.insert(make_pair(y, x));break;}}if (dd == 2) break;}}}return false;}int main() {int h, w; cin >> h >> w;vector<string> f(h); repeat (y,h) cin >> f[y];cout << (solve(h, w, f) ? "YES" : "NO") << endl;return 0;}