結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-23 14:12:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 3,000 ms |
| コード長 | 1,117 bytes |
| コンパイル時間 | 1,993 ms |
| コンパイル使用メモリ | 199,876 KB |
| 最終ジャッジ日時 | 2025-02-07 13:52:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#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;
}