結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-21 00:28:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 3,000 ms |
| コード長 | 1,399 bytes |
| コンパイル時間 | 2,208 ms |
| コンパイル使用メモリ | 209,304 KB |
| 最終ジャッジ日時 | 2025-01-29 12:20:53 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, W, X, Y;
cin >> H >> W >> X >> Y;
X--, Y--;
V<V<ll>> A(H, V<ll>(W));
rep(i, H) rep(j, W) cin >> A[i][j];
priority_queue<tuple<ll, int, int>> que;
V<V<int>> vis(H, V<int>(W, 0));
ll s = A[X][Y];
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
rep(k, 4) {
int nx = X + dx[k], ny = Y + dy[k];
if (0 <= nx && nx < H && 0 <= ny && ny < W) {
que.push({-A[nx][ny], nx, ny});
vis[nx][ny] = 1;
}
}
vis[X][Y] = 1;
int cnt = 1;
while (!que.empty()) {
auto [a, i, j] = que.top();
que.pop();
a = -a;
if (s > a) {
s += a;
cnt++;
rep(k, 4) {
int nx = i + dx[k], ny = j + dy[k];
if (0 <= nx && nx < H && 0 <= ny && ny < W && vis[nx][ny] == 0) {
que.push({-A[nx][ny], nx, ny});
vis[nx][ny] = 1;
}
}
} else {
break;
}
}
show(cnt, s);
cout << (cnt == H * W ? "Yes" : "No") << '\n';
return 0;
}