結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー umimelumimel
提出日時 2022-05-21 00:09:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 3,000 ms
コード長 1,669 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 182,812 KB
実行使用メモリ 10,268 KB
最終ジャッジ日時 2023-10-20 15:04:17
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 102 ms
5,708 KB
testcase_08 AC 102 ms
5,680 KB
testcase_09 AC 138 ms
5,692 KB
testcase_10 AC 144 ms
5,708 KB
testcase_11 AC 147 ms
5,772 KB
testcase_12 AC 118 ms
5,780 KB
testcase_13 AC 83 ms
5,732 KB
testcase_14 AC 98 ms
10,268 KB
testcase_15 AC 96 ms
10,268 KB
testcase_16 AC 41 ms
5,680 KB
testcase_17 AC 173 ms
10,268 KB
testcase_18 AC 44 ms
5,680 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 125 ms
9,916 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 62 ms
5,736 KB
testcase_25 AC 112 ms
5,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

int main(){
    ll h, w, y, x;
    cin >> h >> w >> y >> x;
    y--; x--;

    vector<vector<ll>> a(h, vector<ll>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];

    priority_queue<pll, vector<pll>, greater<pll>> PQ;
    PQ.push({a[y][x], y*w+x});
    ll di[4] = {0, 1, 0, -1};
    ll dj[4] = {1, 0, -1, 0};

    ll sum = a[y][x];
    rep(k, 4){
        ll next_i = y + di[k];
        ll next_j = x + dj[k];
        if(next_i < 0 || next_j < 0 || h <= next_i || w <= next_j) continue;
        PQ.push({a[next_i][next_j], next_i*w+next_j});
    }

    vector<vector<bool>> check(h, vector<bool>(w, false));
    check[y][x] = true;
    while(!PQ.empty()){
        ll now_i = PQ.top().se/w;
        ll now_j = PQ.top().se%w;
        PQ.pop();

        if(check[now_i][now_j]) continue;
        if(sum <= a[now_i][now_j]){
            cout << "No" << endl;
            return 0;
        }
        check[now_i][now_j] = true;
        sum += a[now_i][now_j];

        rep(k, 4){
            ll next_i = now_i + di[k];
            ll next_j = now_j + dj[k];
            if (next_i < 0 || next_j < 0 || h <= next_i || w <= next_j) continue;
            if(check[next_i][next_j]) continue;
            PQ.push({a[next_i][next_j], next_i*w + next_j});
        }
    }

    cout << "Yes" << endl;
}
0