結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー hourenhouren
提出日時 2022-05-20 22:37:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 3,000 ms
コード長 1,386 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 179,680 KB
実行使用メモリ 9,320 KB
最終ジャッジ日時 2023-10-20 13:23:14
合計ジャッジ時間 3,677 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 50 ms
5,304 KB
testcase_08 AC 32 ms
5,304 KB
testcase_09 AC 53 ms
5,304 KB
testcase_10 AC 59 ms
5,304 KB
testcase_11 AC 60 ms
5,304 KB
testcase_12 AC 54 ms
5,304 KB
testcase_13 AC 45 ms
5,304 KB
testcase_14 AC 53 ms
9,320 KB
testcase_15 AC 52 ms
9,320 KB
testcase_16 AC 19 ms
5,304 KB
testcase_17 AC 82 ms
9,320 KB
testcase_18 AC 18 ms
5,304 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 60 ms
6,800 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 30 ms
5,304 KB
testcase_25 AC 47 ms
5,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, P>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
int H[] = {1,0,-1,0}, W[] = {0,1,0,-1};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,y,x;
    cin >> h >> w >> y >> x;
    x--; y--;
    vector<vector<ll>> a(h,vector<ll>(w));
    rep(i,h)rep(j,w) cin >> a[i][j];
    ll now = a[y][x];
    a[y][x] = -1;
    priority_queue<asc(PP)> pq;
    rep(i,4){
        int nh = y+H[i], nw = x+W[i];
        if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
        pq.push({a[nh][nw], {nh, nw}});
        a[nh][nw] = -1;
    }
    while(pq.size()){
        ll s = pq.top().first;
        tie(y,x) = pq.top().second;
        pq.pop();
        if(s>=now){
            cout << "No\n";
            return 0;
        }
        now += s;
        rep(i,4){
            int nh = y+H[i], nw = x+W[i];
            if(nh<0 || nh>=h || nw<0 || nw>=w || a[nh][nw]<0) continue;
            pq.push({a[nh][nw], {nh, nw}});
            a[nh][nw] = -1;
        }
    }
    cout << "Yes\n";
    return 0;
}
0