結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー karinohitokarinohito
提出日時 2022-05-21 01:11:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 3,000 ms
コード長 1,580 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 217,520 KB
実行使用メモリ 7,428 KB
最終ジャッジ日時 2023-10-20 15:23:33
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 82 ms
5,688 KB
testcase_08 AC 102 ms
5,676 KB
testcase_09 AC 126 ms
5,688 KB
testcase_10 AC 125 ms
5,704 KB
testcase_11 AC 128 ms
5,724 KB
testcase_12 AC 102 ms
5,736 KB
testcase_13 AC 66 ms
5,724 KB
testcase_14 AC 92 ms
7,428 KB
testcase_15 AC 93 ms
7,428 KB
testcase_16 AC 44 ms
5,676 KB
testcase_17 AC 108 ms
7,428 KB
testcase_18 AC 42 ms
5,676 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 78 ms
6,292 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 48 ms
5,704 KB
testcase_25 AC 95 ms
5,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


int main() {

    ll H, W, X, Y;
    cin >> H >> W >> Y >> X;
    X--; Y--;
    vvll A(H, vll(W));
    rep(h, H)rep(w, W) {
        cin >> A[h][w];
    }

    vector<vector<bool>> seen(H, vector<bool>(W, false));
    seen[Y][X] = 0;
    ll PP = A[Y][X];
    A[Y][X] = 0;
    seen[Y][X] = 1;
    priority_queue<pair<ll,ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> Q;
    Q.push({ 0,Y * W + X });
    vll dy = { 1,0,0,-1 };
    vll dx = { 0,1,-1,0 };
    ll an = 0;
    while (!Q.empty()) {
        auto k = Q.top();
        ll P = k.second;
        Q.pop();
        ll y = P / W;
        ll x = P % W;
        //if (seen[y][x])continue;
        if (A[y][x] >= PP) {
            cout << "No" << endl;
            return 0;
        }
        an++;
        PP += A[y][x];
        rep(d, 4) {
            ll ny = y + dy[d];
            ll nx = x + dx[d];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W)continue;
            if (seen[ny][nx])continue;
            Q.push({ A[ny][nx],ny * W + nx });
            seen[ny][nx] = 1;
        }
    }

    cout << (an == H * W ? "Yes" : "No") << endl;


}
0