結果

問題 No.86 TVザッピング(2)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-12 17:16:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,238 ms / 5,000 ms
コード長 1,435 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 150,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 15:00:41
合計ジャッジ時間 3,765 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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++;
			}
			else board[i][j] = 0;
		}
	}
	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++;
					dp[y][x] = turn;

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


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

}
0