結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-05-20 23:29:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 3,000 ms
コード長 1,376 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 182,192 KB
実行使用メモリ 6,112 KB
最終ジャッジ日時 2023-10-20 14:26:50
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 79 ms
4,752 KB
testcase_08 AC 110 ms
4,744 KB
testcase_09 AC 130 ms
4,752 KB
testcase_10 AC 135 ms
4,764 KB
testcase_11 AC 137 ms
4,780 KB
testcase_12 AC 107 ms
4,788 KB
testcase_13 AC 67 ms
4,784 KB
testcase_14 AC 101 ms
6,112 KB
testcase_15 AC 101 ms
6,112 KB
testcase_16 AC 46 ms
4,744 KB
testcase_17 AC 100 ms
6,112 KB
testcase_18 AC 46 ms
4,744 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
5,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 51 ms
4,764 KB
testcase_25 AC 92 ms
4,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.05.20 23:29:04
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


int main() {
    int h,w,x,y; cin >> h >> w >> x >> y;
    x--;y--;
    vector<vector<int>> a(h,vector<int>(w));
    vector<vector<bool>> used(h,vector<bool>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    using P = pair<int,pair<int,int>>;
    priority_queue<P,vector<P>,greater<P>> pq;
    int dx[] = {0,1,0,-1};
    int dy[] = {1,0,-1,0};
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || ny < 0 || nx >= h || ny >= w || used[nx][ny]) continue;
        pq.push({a[nx][ny],{nx,ny}});
        used[nx][ny] = true;
    }
    used[x][y] = true;
    ll total = a[x][y];
    while(!pq.empty()) {
        auto p = pq.top(); pq.pop();
        if (total <= p.first) {
            puts("No");
            return 0;
        }
        total += p.first;
        for (int i = 0; i < 4; i++) {
            int nx = p.second.first + dx[i];
            int ny = p.second.second + dy[i];
            if (nx < 0 || ny < 0 || nx >= h || ny >= w || used[nx][ny]) continue;
            pq.push({a[nx][ny],{nx,ny}});
            used[nx][ny] = true;
        }
    }
    puts("Yes");
    return 0;
}
0