結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー yansi819
提出日時 2024-04-16 04:47:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 154 ms / 3,000 ms
コード長 1,048 bytes
コンパイル時間 4,668 ms
コンパイル使用メモリ 255,508 KB
最終ジャッジ日時 2025-02-21 02:27:10
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int h, w, x, y;
ll a[550][550];
bool f[550][550];
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

void add(ll id) {
  int x = id / w;
  int y = id % w;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (0 > nx || nx >= h || 0 > ny || ny >= w) continue;
    if (f[nx][ny]) continue;
    f[nx][ny] = true;
    pq.push({a[nx][ny], nx * w + ny});
  }
}

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];
  }
  ll at = a[x][y];
  f[x][y] = true;
  add(x * w + y);
  while (!pq.empty()) {
    auto [x, id] = pq.top(); pq.pop();
    if (at > x) {
      at += x;
    } else {
      cout << "No" << endl;
      return 0;
    }
    add(id);
  }
  cout << "Yes" << endl;
  return 0;
}
0