結果
| 問題 | No.86 TVザッピング(2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-20 23:42:54 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 447 ms / 5,000 ms |
| + 511µs | |
| コード長 | 1,315 bytes |
| 記録 | |
| コンパイル時間 | 2,652 ms |
| コンパイル使用メモリ | 346,536 KB |
| 実行使用メモリ | 9,388 KB |
| 最終ジャッジ日時 | 2026-08-20 23:43:00 |
| 合計ジャッジ時間 | 6,009 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
constexpr int DX[4] = {0, -1, 0, 1}, DY[4] = {1, 0, -1, 0};
array<int, 3> G[110][110][4];
int main() {
int N, M;
cin >> N >> M;
vector<string> A(N);
for(int i = 0; i < N; ++i) cin >> A[i];
auto map_check = [&](int x, int y) {
return 0 <= x and x < N and 0 <= y and y < M and A[x][y] == '.';
};
for(int x = 0; x < N; ++x) for(int y = 0; y < M; ++y) for(int d = 0; d < 4; ++d) {
int nx = x + DX[d], ny = y + DY[d];
if(map_check(nx, ny)) {
G[x][y][d] = {nx, ny, d};
continue;
}
int nd = (d + 1) % 4;
nx = x + DX[nd], ny = y + DY[nd];
if(map_check(nx, ny)) {
G[x][y][d] = {nx, ny, nd};
continue;
}
G[x][y][d] = {-1, -1, -1};
}
int Wcnt = 0;
for(int x = 0; x < N; ++x) for(int y = 0; y < M; ++y) if(A[x][y] == '.') Wcnt += 1;
for(int sx = 0; sx < N; ++sx) for(int sy = 0; sy < M; ++sy) for(int sd = 0; sd < 4; ++sd) {
if(G[sx][sy][sd][2] == -1) continue;
int cnt = 0;
vector seen(N, vector<bool>(M, 0));
int x = sx, y = sy, d = sd;
do {
const auto v = G[x][y][d];
x = v[0], y = v[1], d = v[2], cnt += 1;
if(d == -1 or seen[x][y]) {
cnt = -1;
break;
}
seen[x][y] = 1;
} while(x != sx or y != sy);
if(cnt == Wcnt) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}