結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー atjh16atjh16
提出日時 2022-09-23 14:12:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 3,000 ms
コード長 1,117 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 207,092 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2023-08-23 20:50:04
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 77 ms
5,552 KB
testcase_08 AC 101 ms
5,296 KB
testcase_09 AC 129 ms
5,560 KB
testcase_10 AC 132 ms
5,692 KB
testcase_11 AC 130 ms
5,652 KB
testcase_12 AC 103 ms
5,652 KB
testcase_13 AC 65 ms
5,896 KB
testcase_14 AC 91 ms
7,260 KB
testcase_15 AC 93 ms
7,252 KB
testcase_16 AC 43 ms
5,320 KB
testcase_17 AC 102 ms
7,424 KB
testcase_18 AC 43 ms
5,324 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 82 ms
6,276 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 52 ms
5,564 KB
testcase_25 AC 92 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int h, w, x, y;
long long z;
long long a[500][500];
bool f[500][500];
typedef pair<long long, pair<int, int>> P;
priority_queue<P, vector<P>, greater<P>> Q;

int main() {
	cin >> h >> w >> x >> y;
	x--;
	y--;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	
	Q.push(make_pair(0, make_pair(x, y)));
	f[x][y] = 1;
	z = a[x][y];

	while (!Q.empty()) {
		long long c = Q.top().first;

		if (z <= c)
			break;
		else
			z += c;

		int d = Q.top().second.first, e = Q.top().second.second;
		Q.pop();

		if (d > 0 && !f[d - 1][e]) {
			f[d - 1][e] = 1;
			Q.push(make_pair(a[d - 1][e], make_pair(d - 1, e)));
		}

		if (d < h - 1 && !f[d + 1][e]) {
			f[d + 1][e] = 1;
			Q.push(make_pair(a[d + 1][e], make_pair(d + 1, e)));
		}

		if (e > 0 && !f[d][e - 1]) {
			f[d][e - 1] = 1;
			Q.push(make_pair(a[d][e - 1], make_pair(d, e - 1)));
		}

		if (e < w - 1 && !f[d][e + 1]) {
			f[d][e + 1] = 1;
			Q.push(make_pair(a[d][e + 1], make_pair(d, e + 1)));
		}
	}

	if (Q.empty())
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
0