結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー monnumonnu
提出日時 2022-05-20 22:33:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 3,000 ms
コード長 1,294 bytes
コンパイル時間 4,420 ms
コンパイル使用メモリ 236,688 KB
実行使用メモリ 8,464 KB
最終ジャッジ日時 2023-10-20 13:19:40
合計ジャッジ時間 6,831 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 81 ms
6,732 KB
testcase_08 AC 104 ms
6,724 KB
testcase_09 AC 125 ms
6,732 KB
testcase_10 AC 128 ms
6,748 KB
testcase_11 AC 130 ms
6,756 KB
testcase_12 AC 101 ms
6,780 KB
testcase_13 AC 61 ms
6,764 KB
testcase_14 AC 96 ms
8,464 KB
testcase_15 AC 96 ms
8,464 KB
testcase_16 AC 46 ms
6,724 KB
testcase_17 AC 104 ms
8,464 KB
testcase_18 AC 45 ms
6,724 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 78 ms
7,284 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 48 ms
6,748 KB
testcase_25 AC 95 ms
6,748 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:44:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   44 |     auto [a,v]=pq.top();
      |          ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 3000
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000000
//#define INF 1000000000000000000

int di[4]={1,0,-1,0};
int dj[4]={0,1,0,-1};

int main(){
  int H,W,Y,X;
  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++){
      cin>>A[i][j];
    }
  }

  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
  vector<vector<int>> seen(H,vector<int>(W,0));

  seen[Y][X]=1;
  ll sum=A[Y][X];

  for(int k=0;k<4;k++){
    int ni=Y+di[k];
    int nj=X+dj[k];
    if(ni<0||nj<0||ni>=H||nj>=W){
      continue;
    }
    pq.push(make_pair(A[ni][nj],ni*W+nj));
    seen[ni][nj]=1;
  }

  while(!pq.empty()){
    auto [a,v]=pq.top();
    int i=v/W;
    int j=v%W;
    pq.pop();
    if(sum<=a){
      cout<<"No"<<'\n';
      return 0;
    }
    sum+=a;
    for(int k=0;k<4;k++){
      int ni=i+di[k];
      int nj=j+dj[k];
      if(ni<0||nj<0||ni>=H||nj>=W){
        continue;
      }
      if(seen[ni][nj]==1){
        continue;
      }
      seen[ni][nj]=1;
      pq.push(make_pair(A[ni][nj],ni*W+nj));
    }
  }

  cout<<"Yes"<<'\n';
}
0