結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー erbowlerbowl
提出日時 2022-08-07 21:05:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 3,000 ms
コード長 1,388 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 218,744 KB
実行使用メモリ 9,516 KB
最終ジャッジ日時 2023-10-17 15:43:22
合計ジャッジ時間 7,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 80 ms
5,688 KB
testcase_08 AC 106 ms
5,668 KB
testcase_09 AC 125 ms
5,688 KB
testcase_10 AC 127 ms
5,712 KB
testcase_11 AC 129 ms
5,748 KB
testcase_12 AC 98 ms
5,760 KB
testcase_13 AC 62 ms
5,740 KB
testcase_14 AC 98 ms
9,516 KB
testcase_15 AC 99 ms
9,516 KB
testcase_16 AC 45 ms
5,668 KB
testcase_17 AC 100 ms
9,516 KB
testcase_18 AC 43 ms
5,668 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 82 ms
6,996 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 48 ms
5,712 KB
testcase_25 AC 90 ms
5,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef tuple<ll,ll,ll> tll;

signed main(){
    ll h,w,y,x;
    std::cin >> h>>w>>y>>x;
    y--;x--;
    vector<vector<ll>> a(h,vector<ll>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
        }
    }
    vector<vector<bool>> used(h,vector<bool>(w));
    ll now = a[y][x];
    used[y][x]= true;
    priority_queue<tll,vector<tll>,greater<tll>> pq;
    
    for (int xx = -1, yy = 0, i = 0; i < 4; xx += yy, yy = xx - yy, xx =yy - xx, ++i) {
        if(x+xx>=0&&x+xx<w&&y+yy>=0&&y+yy<h){
            pq.push({a[y+yy][x+xx],y+yy,x+xx});
            used[y+yy][x+xx]=true;
        }
    }
    bool make=false;
    while(!pq.empty()){
        auto [val, ny, nx] = pq.top();pq.pop();
        if(val>=now){
            make=true;
            break;
        }
        now += val;
        for (int xx = -1, yy = 0, i = 0; i < 4; xx += yy, yy = xx - yy, xx =yy - xx, ++i) {
            if(nx+xx>=0&&nx+xx<w&&ny+yy>=0&&ny+yy<h){
                if(used[ny+yy][nx+xx])continue;
                pq.push({a[ny+yy][nx+xx],ny+yy,nx+xx});
                used[ny+yy][nx+xx]=true;
            }
        }
    }
    if(!make){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}
0