結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー take000take000
提出日時 2022-05-20 23:08:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 3,000 ms
コード長 1,288 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 219,164 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2023-10-20 14:02:12
合計ジャッジ時間 4,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 49 ms
5,700 KB
testcase_08 AC 32 ms
5,684 KB
testcase_09 AC 61 ms
5,700 KB
testcase_10 AC 65 ms
5,716 KB
testcase_11 AC 66 ms
5,736 KB
testcase_12 AC 59 ms
5,748 KB
testcase_13 AC 51 ms
5,732 KB
testcase_14 AC 51 ms
7,368 KB
testcase_15 AC 51 ms
7,368 KB
testcase_16 AC 18 ms
5,684 KB
testcase_17 AC 83 ms
7,368 KB
testcase_18 AC 19 ms
5,684 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 67 ms
6,228 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 33 ms
5,716 KB
testcase_25 AC 49 ms
5,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int H, W, sy, sx;
    cin >> H >> W >> sy >> sx;
    vector A(H, vector<ll>(W));
    rep(i, H) rep(j, W) cin >> A[i][j];

    sy--, sx--;
    vector seen(H, vector<bool>(W));
    seen[sy][sx] = true;
    vector knock(H, vector<bool>(W));

    using T = tuple<ll, int, int>;
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push({A[sy][sx], sy, sx});

    ll cur = 0;
    while (!pq.empty()) {
        auto [enemy, y, x] = pq.top();
        pq.pop();

        if (!(y == sy && x == sx) && enemy >= cur)
            break;

        knock[y][x] = true;
        cur += enemy;

        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W)
                continue;
            if (seen[ny][nx])
                continue;
            seen[ny][nx] = true;
            pq.push({A[ny][nx], ny, nx});
        }
    }

    rep(i, H) rep(j, W) {
        if (!knock[i][j]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

    return 0;
}
0