結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー Nzt3Nzt3
提出日時 2022-05-21 16:00:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 3,000 ms
コード長 932 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 181,908 KB
実行使用メモリ 5,932 KB
最終ジャッジ日時 2023-10-20 16:19:34
合計ジャッジ時間 3,613 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 44 ms
4,632 KB
testcase_08 AC 30 ms
4,620 KB
testcase_09 AC 58 ms
4,632 KB
testcase_10 AC 61 ms
4,644 KB
testcase_11 AC 63 ms
4,660 KB
testcase_12 AC 59 ms
4,668 KB
testcase_13 AC 47 ms
4,664 KB
testcase_14 AC 45 ms
5,932 KB
testcase_15 AC 47 ms
5,932 KB
testcase_16 AC 18 ms
4,620 KB
testcase_17 AC 67 ms
5,932 KB
testcase_18 AC 17 ms
4,620 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 54 ms
5,168 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 31 ms
4,644 KB
testcase_25 AC 45 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W,sH,sW;
  cin>>H>>W>>sH>>sW;
  vector<vector<int>>A(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int &j:A[i])cin>>j;
  }
  --sH,--sW;
  long long P=A[sH][sW];
  int dh[4]={0,1,0,-1};
  int dw[4]={-1,0,1,0};
  vector<vector<bool>>vst(H,vector<bool>(W));
  vst[sH][sW]=true;
  priority_queue<pair<int,array<int,2>>,vector<pair<int,array<int,2>>>,greater<pair<int,array<int,2>>>>pq;
  pq.push({0,{sH,sW}});
  while(pq.size()){
    int h=pq.top().second[0],w=pq.top().second[1],k=pq.top().first;
    pq.pop();
    if(k>=P){
      cout<<"No\n";
      return 0;
    }
    P+=k;
    for(int i=0;i<4;i++){
      if(h+dh[i]>=0&&h+dh[i]<H&&w+dw[i]>=0&&w+dw[i]<W&&!vst[h+dh[i]][w+dw[i]]){
        vst[h+dh[i]][w+dw[i]]=true;
        pq.push({A[h+dh[i]][w+dw[i]],{h+dh[i],w+dw[i]}});
      }
    }
  }
  cout<<"Yes\n";
}
0