結果

問題 No.86 TVザッピング(2)
ユーザー pekempeypekempey
提出日時 2016-02-18 06:57:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,379 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 146,724 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 15:02:17
合計ジャッジ時間 2,502 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,500 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = R <= 1;
	rep(i, h) rep(j, w) all &= g[i][j] == '#';

	cout << (all ? "YES" : "NO") << endl;

	return 0;
}
0