結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー umimelumimel
提出日時 2022-05-21 00:03:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,649 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 182,784 KB
実行使用メモリ 5,692 KB
最終ジャッジ日時 2023-10-20 14:56:42
合計ジャッジ時間 3,922 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 49 ms
5,672 KB
testcase_08 AC 106 ms
5,672 KB
testcase_09 AC 102 ms
5,672 KB
testcase_10 AC 100 ms
5,672 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 37 ms
5,664 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 42 ms
5,672 KB
testcase_17 AC 43 ms
5,672 KB
testcase_18 AC 43 ms
5,672 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 70 ms
5,672 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 d = PQ.top().fi;
        ll now_i = PQ.top().se/w;
        ll now_j = PQ.top().se%w;
        PQ.pop();

        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 = y + di[k];
            ll next_j = x + 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