結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー nawawannawawan
提出日時 2022-05-20 23:11:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 3,000 ms
コード長 1,282 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 100,828 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2023-10-20 14:03:41
合計ジャッジ時間 3,744 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 81 ms
5,764 KB
testcase_08 AC 108 ms
5,752 KB
testcase_09 AC 129 ms
5,764 KB
testcase_10 AC 131 ms
5,780 KB
testcase_11 AC 135 ms
5,800 KB
testcase_12 AC 104 ms
5,812 KB
testcase_13 AC 65 ms
5,800 KB
testcase_14 AC 101 ms
7,504 KB
testcase_15 AC 101 ms
7,504 KB
testcase_16 AC 46 ms
5,752 KB
testcase_17 AC 101 ms
7,504 KB
testcase_18 AC 46 ms
5,752 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 86 ms
6,368 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 52 ms
5,780 KB
testcase_25 AC 97 ms
5,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <tuple>
using namespace std;
int main()
{
    int H, W, Y, X;
    cin >> H >> W >> Y >> X;
    Y--;
    X--;
    vector<vector<long long>> A(H, vector<long long>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
            cin >> A[i][j];
    }
    priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int>>, greater<tuple<long long, int, int>>> q;
    int cnt = 0;
    long long sum = A[Y][X];
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    vector<vector<bool>> used(H, vector<bool>(W, false));
    q.push({0, Y, X});
    used[Y][X] = true;
    while (!q.empty())
    {
        auto [num, x, y] = q.top();
        q.pop();
        if (num >= sum)
            break;
        sum += num;
        cnt++;
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && !used[nx][ny])
            {
                q.push({A[nx][ny], nx, ny});
                used[nx][ny] = true;
            }
        }
    }
    if (cnt == H * W)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
0