結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-18 06:56:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,377 bytes |
| コンパイル時間 | 1,112 ms |
| コンパイル使用メモリ | 159,424 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:59:28 |
| 合計ジャッジ時間 | 1,932 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;
int h, w;
string g[111];
char isWall(int y, int x) {
if (y < 0 || y >= h || x < 0 || x >= w) return true;
return g[y][x] == '#';
}
int main() {
cin >> h >> w;
rep(i, h) cin >> g[i];
pair<int, int> start(1e9, 1e9);
rep(i, h) rep(j, w) if (g[i][j] == '.') chmin(start, make_pair(i, j));
int sy = start.first;
int sx = start.second;
const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };
int y = sy;
int x = sx;
int dir = 1;
int R = 0;
int L = 0;
while (true) {
while (!isWall(y + dy[dir], x + dx[dir])) {
y += dy[dir];
x += dx[dir];
g[y][x] = '#';
}
int ld = (dir + 3) % 4;
int rd = (dir + 1) % 4;
if (!isWall(y + dy[rd], x + dx[rd])) {
dir = rd;
R++;
} else if (!isWall(y + dy[ld], x + dx[ld])) {
dir = ld;
L++;
} else break;
}
bool all = true;
rep(i, h) rep(j, w) all &= g[i][j] == '#';
cout << (all ? "YES" : "NO") << endl;
return 0;
}