結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー kai4096_donkai4096_don
提出日時 2022-05-20 23:01:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 3,000 ms
コード長 1,973 bytes
コンパイル時間 3,861 ms
コンパイル使用メモリ 236,716 KB
実行使用メモリ 15,504 KB
最終ジャッジ日時 2023-10-20 13:55:04
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 85 ms
7,688 KB
testcase_08 AC 110 ms
7,664 KB
testcase_09 AC 139 ms
7,688 KB
testcase_10 AC 139 ms
7,688 KB
testcase_11 AC 140 ms
7,720 KB
testcase_12 AC 111 ms
7,740 KB
testcase_13 AC 71 ms
7,700 KB
testcase_14 AC 133 ms
15,504 KB
testcase_15 AC 132 ms
15,504 KB
testcase_16 AC 47 ms
7,664 KB
testcase_17 AC 122 ms
12,856 KB
testcase_18 AC 48 ms
7,664 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 94 ms
10,796 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 55 ms
7,692 KB
testcase_25 AC 109 ms
7,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
typedef long long ll;
int main() {
    ll h,w,x,y;
    cin >> h >> w >> x >> y;
    x--,y--;
    vector<vector<ll>> vviNum(h,vector<ll>(w,0));
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            cin >> vviNum[i][j];
        }
    }
    
    multimap<ll,ll> siTmp;
    vector<vector<ll>> vviCheck(h,vector<ll>(w,0));
    ll nTmp = vviNum[x][y];
    vviCheck[x][y] = 1;
    if(x > 0){
        siTmp.insert(make_pair(vviNum[x-1][y], (x-1)*w+y));
        vviCheck[x-1][y] = 1;
    }
    if(y > 0){
        siTmp.insert(make_pair(vviNum[x][y-1], x*w+y-1));
        vviCheck[x][y-1] = 1;
    }
    if(x < h-1){
        siTmp.insert(make_pair(vviNum[x+1][y], (x+1)*w+y));
        vviCheck[x+1][y] = 1;
    }
    if(y < w-1){
        siTmp.insert(make_pair(vviNum[x][y+1], x*w+y+1));
        vviCheck[x][y+1] = 1;
    }
    while(!siTmp.empty()){
        auto itr = siTmp.begin();
        if(itr->first >= nTmp){
            break;
        }
        nTmp += itr->first;
        ll i = itr->second / w;
        ll j = itr->second % w;
        siTmp.erase(itr);
        if(i > 0 && vviCheck[i-1][j] == 0){
            siTmp.insert(make_pair(vviNum[i-1][j], (i-1)*w+j));
            vviCheck[i-1][j] = 1;
        }
        if(j > 0 && vviCheck[i][j-1] == 0){
            siTmp.insert(make_pair(vviNum[i][j-1], i*w+j-1));
            vviCheck[i][j-1] = 1;
        }
        if(i < h-1 && vviCheck[i+1][j] == 0){
            siTmp.insert(make_pair(vviNum[i+1][j], (i+1)*w+j));
            vviCheck[i+1][j] = 1;
        }
        if(j < w-1 && vviCheck[i][j+1] == 0){
            siTmp.insert(make_pair(vviNum[i][j+1], i*w+j+1));
            vviCheck[i][j+1] = 1;
        }
    }
    
    if(siTmp.empty()){
        cout << "Yes" <<endl;
    }else {
        cout << "No" <<endl;
    }
    return 0;
}
0