結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-29 15:18:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 3,000 ms
コード長 1,251 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 212,388 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-09-20 10:41:21
合計ジャッジ時間 7,002 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 78 ms
5,548 KB
testcase_08 AC 104 ms
5,408 KB
testcase_09 AC 123 ms
5,360 KB
testcase_10 AC 128 ms
5,452 KB
testcase_11 AC 129 ms
5,468 KB
testcase_12 AC 101 ms
5,604 KB
testcase_13 AC 64 ms
5,540 KB
testcase_14 AC 98 ms
8,236 KB
testcase_15 AC 98 ms
8,304 KB
testcase_16 AC 43 ms
5,344 KB
testcase_17 AC 102 ms
8,092 KB
testcase_18 AC 43 ms
5,388 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 82 ms
6,632 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 50 ms
5,512 KB
testcase_25 AC 92 ms
5,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;

int main(){

    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    ll H, W, Y, X, cnt=1, now, h, w, nh, nw, e;
    cin >> H >> W >> Y >> X;
    vector<vector<ll>> A(H+1, vector<ll>(W+1));
    pq<tuple<ll, ll, ll>> que;

    for (int i=1; i<=H; i++){
        for (int j=1; j<=W; j++) cin >> A[i][j];
    }

    now = A[Y][X];
    A[Y][X] = 0;
    h = Y; w = X;
    for (int i=0; i<4; i++){
        nh = h+dx[i]; nw = w+dy[i];
        if (nh == 0 || nw == 0 || nh == H+1 || nw == W+1) continue;
        que.push({A[nh][nw], nh, nw});
        A[nh][nw] = 0;
    }

    while(!que.empty()){
        tie(e, h, w) = que.top();
        que.pop();
        if (e >= now){
            cout << "No" << endl;
            return 0;
        }
        now += e;
        cnt++;
        for (int i=0; i<4; i++){
            nh = h+dx[i]; nw = w+dy[i];
            if (nh == 0 || nw == 0 || nh == H+1 || nw == W+1) continue;
            if (A[nh][nw] == 0) continue;
            que.push({A[nh][nw], nh, nw});
            A[nh][nw] = 0;
        }
    }

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

    return 0;
}
0