結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー yansi819yansi819
提出日時 2024-04-16 04:47:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 3,000 ms
コード長 1,048 bytes
コンパイル時間 5,223 ms
コンパイル使用メモリ 257,832 KB
実行使用メモリ 7,876 KB
最終ジャッジ日時 2024-04-16 04:48:07
合計ジャッジ時間 7,872 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 91 ms
6,944 KB
testcase_08 AC 112 ms
6,944 KB
testcase_09 AC 137 ms
6,944 KB
testcase_10 AC 140 ms
6,944 KB
testcase_11 AC 142 ms
6,940 KB
testcase_12 AC 109 ms
6,944 KB
testcase_13 AC 66 ms
6,944 KB
testcase_14 AC 103 ms
7,872 KB
testcase_15 AC 104 ms
7,876 KB
testcase_16 AC 47 ms
6,940 KB
testcase_17 AC 109 ms
7,856 KB
testcase_18 AC 47 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 87 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 52 ms
6,940 KB
testcase_25 AC 102 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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