結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー RVindicatioRVindicatio
提出日時 2022-05-20 22:27:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 3,000 ms
コード長 1,547 bytes
コンパイル時間 3,622 ms
コンパイル使用メモリ 236,536 KB
実行使用メモリ 12,128 KB
最終ジャッジ日時 2023-10-20 13:12:00
合計ジャッジ時間 5,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 73 ms
5,728 KB
testcase_08 AC 32 ms
5,696 KB
testcase_09 AC 84 ms
5,728 KB
testcase_10 AC 90 ms
5,756 KB
testcase_11 AC 93 ms
5,796 KB
testcase_12 AC 87 ms
5,800 KB
testcase_13 AC 77 ms
5,784 KB
testcase_14 AC 87 ms
12,128 KB
testcase_15 AC 87 ms
12,128 KB
testcase_16 AC 19 ms
5,696 KB
testcase_17 AC 144 ms
11,384 KB
testcase_18 AC 19 ms
5,696 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 97 ms
8,192 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 46 ms
5,756 KB
testcase_25 AC 73 ms
5,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

template<typename T>
bool chmin(T& x, const T& y){
  if(x <= y) return false;
  x = y;
  return true;
}
template<typename T>
bool chmax(T& x, const T& y){
  if(x >= y) return false;
  x = y;
  return true;
}

void solve() {
  ll h, w, y, x; cin >> h >> w >> y >> x;
  y--; x--;
  vector<vector<ll>> a(h, vector<ll>(w));
  for (int i=0; i<h; i++) for (int j=0; j<w; j++) cin >> a[i][j];
  ll lv = a[y][x];
  priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>> q;
  vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  vector<vector<bool>> v(h, vector<bool>(w, false));
  v[y][x] = true;
  for (int k=0; k<4; k++) {
    int nx = y + dx[k], ny = x + dy[k];
    if (0 <= nx && nx < h && 0 <= ny && ny < w) {
      q.push({a[nx][ny], nx, ny});
      v[nx][ny] = true;
    }
  }
  while (q.size()) {
    auto now = q.top(); q.pop();
    int i = now[1], j = now[2];
    ll p = now[0];
    if (lv <= p) {
      cout << "No" << '\n';
      return;
    }
    lv += p;
    for (int k=0; k<4; k++) {
      int nx = i + dx[k], ny = j + dy[k];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && !v[nx][ny]) {
        v[nx][ny] = true;
        q.push({a[nx][ny], nx, ny});
      }
    }
  }
  cout << "Yes" << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // int t; cin >> t;
  /*while (t--)*/ solve();
}
0