結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー umezoumezo
提出日時 2022-05-20 23:18:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 203,380 KB
実行使用メモリ 9,628 KB
最終ジャッジ日時 2023-10-20 14:11:01
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,736 KB
testcase_01 AC 2 ms
5,728 KB
testcase_02 AC 3 ms
5,720 KB
testcase_03 AC 3 ms
5,752 KB
testcase_04 AC 2 ms
5,728 KB
testcase_05 AC 2 ms
5,724 KB
testcase_06 AC 2 ms
5,728 KB
testcase_07 AC 22 ms
8,436 KB
testcase_08 AC 34 ms
8,436 KB
testcase_09 AC 35 ms
8,436 KB
testcase_10 AC 35 ms
9,628 KB
testcase_11 AC 35 ms
9,624 KB
testcase_12 AC 28 ms
9,628 KB
testcase_13 AC 27 ms
9,244 KB
testcase_14 AC 28 ms
9,628 KB
testcase_15 AC 26 ms
8,436 KB
testcase_16 AC 2 ms
5,740 KB
testcase_17 AC 3 ms
8,436 KB
testcase_18 AC 2 ms
5,820 KB
testcase_19 AC 3 ms
5,796 KB
testcase_20 AC 29 ms
9,628 KB
testcase_21 AC 28 ms
9,620 KB
testcase_22 AC 25 ms
9,628 KB
testcase_23 AC 23 ms
8,436 KB
testcase_24 AC 24 ms
9,628 KB
testcase_25 AC 32 ms
9,580 KB
testcase_26 AC 34 ms
9,628 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;

ll dp[505][505],dp1[505][505];
ll A[505][505];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  rep(i,h) rep(j,w) cin>>A[i][j];
  
  dp[0][0]=A[0][0];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i-1>=0 && dp[i-1][j]>A[i][j]) dp[i][j]=max(dp[i][j],dp[i-1][j]+A[i][j]);
      if(j-1>=0 && dp[i][j-1]>A[i][j]) dp[i][j]=max(dp[i][j],dp[i][j-1]+A[i][j]);
      if(i-1>=0 && dp1[i-1][j]>A[i][j]) dp1[i][j]=max(dp1[i][j],dp1[i-1][j]+A[i][j]);
      if(j-1>=0 && dp1[i][j-1]>A[i][j]) dp1[i][j]=max(dp1[i][j],dp1[i][j-1]+A[i][j]);
      if(i-1>=0 && dp[i-1][j]<=A[i][j] && (i!=h-1 || j!=w-1)) dp1[i][j]=max(dp1[i][j],dp[i-1][j]);
      if(j-1>=0 && dp[i][j-1]<=A[i][j] && (i!=h-1 || j!=w-1)) dp1[i][j]=max(dp1[i][j],dp[i][j-1]);
    }
  }
  if(dp[h-1][w-1]>0 || dp1[h-1][w-1]>0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}
0