結果

問題 No.86 TVザッピング(2)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-12 17:12:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 149,776 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 19:41:39
合計ジャッジ時間 4,905 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;


bool check(){
	int H, W;
	cin >> H >> W;
	vector<vector<int>> board(H, vector<int>(W));
	string s;
	int button = 0;
	for (int i = 0; i < H; i++)
	{
		cin >> s;
		for (int j = 0; j < W; j++)
		{
			if (s[j] == '#'){
				board[i][j] = 1;
				button++;
			}
		}
	}
	if (button == 0) return false;

	vector<vector<int>> dp(H, vector<int>(W));
	int turn = 0;
	int dk = 0;
	int dy[] {1, 0, -1, 0};
	int dx[] {0, 1, 0, -1};
	for (int t = 1; t < 4; t += 2){
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (!board[i][j]) continue;
				for (int k = 0; k < 4; k++)
				{
					dk = k;
					int count = 1;
					int y = i;
					int x = j;
					turn++;

					while (true){
						int ny, nx;
						ny = y + dy[dk];
						nx = x + dx[dk];
						if (nx < 0 || ny < 0 || nx >= W || ny >= H || board[nx][nx] == 0 || dp[ny][nx] == turn){
							dk += t;
							if (dk >= 4) dk -= 4;
							ny = y + dy[dk];
							nx = x + dx[dk];
							if (nx < 0 || ny < 0 || nx >= W || ny >= H || board[nx][nx] == 0 || dp[ny][nx] == turn) break;
						}
						y = ny;
						x = nx;
						dp[y][x] = turn;
						count++;
					}
					if (count == button) return true;
				}
			}
		}
	}
	return false;
}


int main(){
	if (check()) cout << "YES" << endl;
	else cout << "NO" << endl;

}
0