結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー umezoumezo
提出日時 2022-05-20 23:32:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 3,000 ms
コード長 1,018 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 208,848 KB
実行使用メモリ 10,284 KB
最終ジャッジ日時 2023-10-20 14:29:29
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,692 KB
testcase_01 AC 2 ms
5,684 KB
testcase_02 AC 2 ms
5,684 KB
testcase_03 AC 2 ms
5,696 KB
testcase_04 AC 3 ms
5,684 KB
testcase_05 AC 2 ms
5,684 KB
testcase_06 AC 2 ms
5,684 KB
testcase_07 AC 50 ms
6,632 KB
testcase_08 AC 31 ms
5,940 KB
testcase_09 AC 60 ms
6,632 KB
testcase_10 AC 63 ms
6,656 KB
testcase_11 AC 65 ms
6,700 KB
testcase_12 AC 59 ms
6,704 KB
testcase_13 AC 49 ms
6,692 KB
testcase_14 AC 50 ms
10,284 KB
testcase_15 AC 50 ms
10,284 KB
testcase_16 AC 17 ms
5,948 KB
testcase_17 AC 85 ms
10,284 KB
testcase_18 AC 18 ms
5,948 KB
testcase_19 AC 2 ms
5,696 KB
testcase_20 AC 2 ms
5,708 KB
testcase_21 AC 2 ms
5,708 KB
testcase_22 AC 59 ms
7,644 KB
testcase_23 AC 2 ms
5,688 KB
testcase_24 AC 32 ms
6,656 KB
testcase_25 AC 50 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;
typedef pair<ll,pair<ll,ll>> P;

ll A[505][505];
int vis[505][505];

int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w,y,x;
  cin>>h>>w>>y>>x;
  y--,x--;
  rep(i,h) rep(j,w) cin>>A[i][j];
  
  priority_queue<P,vector<P>,greater<P>> que;
  
  auto f=[&](int i,int j){
    rep(k,4){
      int ni=i+dh[k],nj=j+dw[k];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(vis[ni][nj]) continue;
      que.push({A[ni][nj],{ni,nj}});
      vis[ni][nj]=1;
    }     
  };
  
  int cnt=1;
  ll now=A[y][x];
  vis[y][x]=1;
  f(y,x);
  
  while(que.size()){
    auto t=que.top(); que.pop();
    ll a=t.first,i=t.second.first,j=t.second.second;
    if(a<now){
      now+=a;
      f(i,j);
      cnt++;
    }
    else break;
  }
  if(cnt==h*w) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}
0