結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー KKT89KKT89
提出日時 2022-05-21 17:51:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 3,000 ms
コード長 1,873 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 148,312 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2023-10-20 16:28:41
合計ジャッジ時間 3,606 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 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 45 ms
4,640 KB
testcase_08 AC 31 ms
4,624 KB
testcase_09 AC 51 ms
4,640 KB
testcase_10 AC 55 ms
4,656 KB
testcase_11 AC 56 ms
4,680 KB
testcase_12 AC 48 ms
4,688 KB
testcase_13 AC 42 ms
4,680 KB
testcase_14 AC 46 ms
6,400 KB
testcase_15 AC 46 ms
6,400 KB
testcase_16 AC 17 ms
4,624 KB
testcase_17 AC 68 ms
6,400 KB
testcase_18 AC 17 ms
4,624 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 52 ms
5,304 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 28 ms
4,656 KB
testcase_25 AC 41 ms
4,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    int x,y; cin >> x >> y;
    x--; y--;
    vector<vector<int>> a(h,vector<int>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    vector<vector<bool>> done(h,vector<bool>(w,false));
    done[x][y] = 1;
    using P = pair<ll,pair<int,int>>;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push({-1,{x,y}});
    ll cur = 0;
    while(pq.size()){
        auto p = pq.top(); pq.pop();
        if(p.first >= cur){
            cout << "No" << endl;
            return 0;
        }
        int x = p.second.first, y = p.second.second;
        cur += a[x][y];
        for(int i=0;i<4;i++){
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(0 <= nx and nx < h and 0 <= ny and ny < w and !done[nx][ny]){
                done[nx][ny] = 1;
                pq.push({a[nx][ny],{nx,ny}});
            }
        }
    }
    cout << "Yes" << endl;
}


0