結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー keisuke6keisuke6
提出日時 2022-05-21 09:50:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,665 bytes
コンパイル時間 3,009 ms
コンパイル使用メモリ 187,984 KB
実行使用メモリ 9,508 KB
最終ジャッジ日時 2023-10-20 15:46:49
合計ジャッジ時間 4,988 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 101 ms
5,668 KB
testcase_09 AC 127 ms
5,752 KB
testcase_10 WA -
testcase_11 AC 126 ms
5,696 KB
testcase_12 AC 100 ms
5,712 KB
testcase_13 AC 38 ms
5,660 KB
testcase_14 AC 74 ms
5,668 KB
testcase_15 AC 71 ms
5,668 KB
testcase_16 AC 42 ms
5,668 KB
testcase_17 WA -
testcase_18 AC 42 ms
5,668 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 WA -
testcase_23 WA -
testcase_24 AC 49 ms
5,708 KB
testcase_25 AC 96 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define make_pair make_tuple
signed main(){
  int H,W,X,Y;
  cin>>H>>W>>X>>Y;
  X--;
  Y--;
  vector<vector<int>> G(H,vector<int>(W));
  for(int i=0;i<H;i++)for(int j=0;j<W;j++) cin>>G[i][j];
  vector<vector<bool>> U(H,vector<bool>(W));
  priority_queue<tuple<int,int,int>> s;
  U[X][Y] = true;
  int now = G[X][Y];
  int i=X;
  int j=Y;
  if(i != 0 && G[i-1][j] < now && !U[i-1][j]){
    s.push(make_pair(G[i-1][j],i-1,j));
    U[i-1][j] = true;
  }
  if(j != 0 && G[i][j-1] < now && !U[i][j-1]){
    U[i][j-1] = true;
    s.push(make_pair(G[i][j-1],i,j-1));
  }
  if(i != H-1 && G[i+1][j] < now && !U[i+1][j]){
    s.push(make_pair(G[i+1][j],i+1,j));
    U[i+1][j] = true;
  }
  if(j != W-1 && G[i][j+1] < now && !U[i][j+1]){
    U[i][j+1] = true;
    s.push(make_pair(G[i][j+1],i,j+1));
  }
  int count = 1;
  while(!s.empty()){
    count++;
    int a,b,c;
    tie(a,b,c) = s.top();
    /*cout<<b<<' '<<c<<endl;*/
    s.pop();
    if(a > now){
      cout<<"No"<<endl;
      return 0;
    }
    now += a;
    U[b][c] = true;
    i=b;j=c;
    if(i != 0 && G[i-1][j] < now && !U[i-1][j]){
      U[i-1][j] = true;
      s.push(make_pair(G[i-1][j],i-1,j));
    }
    if(j != 0 && G[i][j-1] < now && !U[i][j-1]){
      U[i][j-1] = true;
      s.push(make_pair(G[i][j-1],i,j-1));
    }
    if(i != H-1 && G[i+1][j] < now && !U[i+1][j]){
      U[i+1][j] = true;
      s.push(make_pair(G[i+1][j],i+1,j));
    }
    if(j != W-1 && G[i][j+1] < now && !U[i][j+1]){
      U[i][j+1] = true;
      s.push(make_pair(G[i][j+1],i,j+1));
    }
  }
  if(count == H*W) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
0