結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-01-08 22:47:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,694 bytes |
| コンパイル時間 | 575 ms |
| コンパイル使用メモリ | 69,992 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:59:38 |
| 合計ジャッジ時間 | 1,779 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#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-clockwise
const int dx[] = { 1, 0, -1, 0 };
const int table[] = { 0, 1, 2, 1, 2, 3 };
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 cnt = 0;
for (int phase = 0; phase < 6; ) {
if (cnt and y == y0 and x == x0) break;
++ cnt;
int ny = y + dy[(d0 + table[phase] ) % 4];
int nx = x + dx[(d0 + table[phase] ) % 4];
int ry = y + dy[(d0 + table[phase] + 3) % 4];
int rx = x + dx[(d0 + table[phase] + 3) % 4];
if (phase == 2 and pred(ry, rx)) {
y = ry;
x = rx;
++ phase;
} else if (pred(ny, nx)) {
y = ny;
x = nx;
} else {
-- cnt;
++ phase;
}
}
if (y == y0 and x == x0 and cnt == total) return true;
}
}
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;
}