結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-23 18:19:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 5,000 ms |
| コード長 | 2,406 bytes |
| コンパイル時間 | 1,881 ms |
| コンパイル使用メモリ | 209,504 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 14:00:36 |
| 合計ジャッジ時間 | 2,949 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int128 = __int128_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, n, s) for (int i = 0; i < n; i += s)
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define repsl(i, l, r, s) for (int i = l; i < r; i += s)
#define all(iterable) (iterable).begin(), (iterable).end()
constexpr int dx4[4] = {1, 0, -1, 0};
constexpr int dy4[4] = {0, 1, 0, -1};
constexpr int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
template <typename T>
void print(const vector<T>& vec, const string sep = " ", const string end = "\n") {
int n = vec.size();
rep(i, n) {
cout << vec[i];
if (i < n - 1) cout << sep;
else cout << end;
}
}
template <typename T>
void read(vector<T>& a, int begin_index, int length) {
if (a.size() < begin_index + length) a.resize(begin_index + length);
while (length --> 0) cin >> a[begin_index++];
}
template <typename T>
void read(vector<T>& a) { read(a, 0, a.size()); }
constexpr size_t M = 500010;
int main() {
size_t n, m;
cin >> n >> m;
auto in = [&](int x, int y) { return 0 <= x and x < n and 0 <= y and y < m; };
auto out = [&](int x, int y) { return not in(x, y); };
vector<vector<char>> g(n, vector<char>(m));
size_t k = 0;
for (auto& r : g) {
read(r);
for (char c : r) k += c == '.';
}
vector<vector<bool>> vis(n, vector<bool>(m, false));
rep(i, n) rep(j, m) {
if (g[i][j] == '#') continue;
rep(t, 4) {
for (auto& r : vis) r.assign(m, false);
size_t d = t;
int x = i, y = j;
vis[x][y] = true;
size_t rest = k - 1;
while (true) {
int nx = x + dx4[d], ny = y + dy4[d];
if (out(nx, ny) or g[nx][ny] == '#') {
d = (d + 1) & 3;
nx = x + dx4[d], ny = y + dy4[d];
}
if (in(nx, ny) and g[nx][ny] == '.') {
x = nx, y = ny;
if (vis[x][y]) break;
vis[x][y] = true;
--rest;
} else break;
}
if (rest == 0 and x == i and y == j) {
cout << "YES\n";
return 0;
}
}
}
cout << "NO\n";
return 0;
}