結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ruthenruthen
提出日時 2022-05-21 00:28:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 3,000 ms
コード長 1,399 bytes
コンパイル時間 3,373 ms
コンパイル使用メモリ 216,176 KB
実行使用メモリ 8,208 KB
最終ジャッジ日時 2023-10-20 15:15:30
合計ジャッジ時間 4,121 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 44 ms
6,024 KB
testcase_08 AC 29 ms
6,024 KB
testcase_09 AC 58 ms
6,288 KB
testcase_10 AC 56 ms
6,024 KB
testcase_11 AC 58 ms
6,560 KB
testcase_12 AC 51 ms
6,288 KB
testcase_13 AC 40 ms
6,288 KB
testcase_14 AC 47 ms
8,208 KB
testcase_15 AC 44 ms
8,208 KB
testcase_16 AC 16 ms
6,024 KB
testcase_17 AC 74 ms
8,208 KB
testcase_18 AC 18 ms
6,024 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 55 ms
7,028 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 28 ms
6,024 KB
testcase_25 AC 44 ms
6,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W, X, Y;
    cin >> H >> W >> X >> Y;
    X--, Y--;
    V<V<ll>> A(H, V<ll>(W));
    rep(i, H) rep(j, W) cin >> A[i][j];
    priority_queue<tuple<ll, int, int>> que;
    V<V<int>> vis(H, V<int>(W, 0));
    ll s = A[X][Y];
    const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    rep(k, 4) {
        int nx = X + dx[k], ny = Y + dy[k];
        if (0 <= nx && nx < H && 0 <= ny && ny < W) {
            que.push({-A[nx][ny], nx, ny});
            vis[nx][ny] = 1;
        }
    }
    vis[X][Y] = 1;
    int cnt = 1;
    while (!que.empty()) {
        auto [a, i, j] = que.top();
        que.pop();
        a = -a;
        if (s > a) {
            s += a;
            cnt++;
            rep(k, 4) {
                int nx = i + dx[k], ny = j + dy[k];
                if (0 <= nx && nx < H && 0 <= ny && ny < W && vis[nx][ny] == 0) {
                    que.push({-A[nx][ny], nx, ny});
                    vis[nx][ny] = 1;
                }
            }
        } else {
            break;
        }
    }
    show(cnt, s);
    cout << (cnt == H * W ? "Yes" : "No") << '\n';
    return 0;
}
0