結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー RVindicatioRVindicatio
提出日時 2022-05-20 22:19:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 3,894 ms
コンパイル使用メモリ 225,504 KB
実行使用メモリ 19,020 KB
最終ジャッジ日時 2023-10-20 13:02:50
合計ジャッジ時間 5,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 42 ms
19,020 KB
testcase_08 AC 53 ms
19,020 KB
testcase_09 AC 54 ms
19,020 KB
testcase_10 AC 56 ms
19,020 KB
testcase_11 AC 54 ms
18,756 KB
testcase_12 AC 47 ms
19,020 KB
testcase_13 AC 47 ms
19,020 KB
testcase_14 AC 48 ms
19,020 KB
testcase_15 AC 47 ms
19,020 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 50 ms
19,020 KB
testcase_21 AC 49 ms
18,756 KB
testcase_22 AC 44 ms
19,020 KB
testcase_23 AC 44 ms
19,020 KB
testcase_24 AC 44 ms
19,020 KB
testcase_25 AC 52 ms
18,228 KB
testcase_26 AC 54 ms
19,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

template<typename T>
bool chmin(T& x, const T& y){
  if(x <= y) return false;
  x = y;
  return true;
}
template<typename T>
bool chmax(T& x, const T& y){
  if(x >= y) return false;
  x = y;
  return true;
}

void solve() {
  int h, w; cin >> h >> w;
  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];
  vector<vector<vector<ll>>> dp(h, vector<vector<ll>>(w, vector<ll>(2, -inf)));
  dp[0][0][0] = a[0][0];
  for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
    if (i-1 >= 0) {
      if (dp[i-1][j][0] > a[i][j]) {
        chmax(dp[i][j][0], dp[i-1][j][0] + a[i][j]);
      } else {
        chmax(dp[i][j][1], dp[i-1][j][0]);
      }
      if (dp[i-1][j][1] > a[i][j]) {
        chmax(dp[i][j][1], dp[i-1][j][1] + a[i][j]);
      }
    }
    if (j-1 >= 0) {
      if (dp[i][j-1][0] > a[i][j]) {
        chmax(dp[i][j][0], dp[i][j-1][0] + a[i][j]);
      } else {
        chmax(dp[i][j][1], dp[i][j-1][0]);
      }
      if (dp[i][j-1][1] > a[i][j]) {
        chmax(dp[i][j][1], dp[i][j-1][1] + a[i][j]);
      }
    }
  }
  // for (int i=0; i<h; i++) {
  //   for (int j=0; j<w; j++) {
  //     cout << dp[i][j][0] << " ";
  //   }
  //   cout << endl;
  // }
  // for (int i=0; i<h; i++) {
  //   for (int j=0; j<w; j++) {
  //     cout << dp[i][j][1] << " ";
  //   }
  //   cout << endl;
  // }
  ll ma = max({dp[h-2][w-1][0], dp[h-2][w-1][1], dp[h-1][w-2][0], dp[h-1][w-2][1]});
  cout << (ma > a[h-1][w-1] ? "Yes" : "No") << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // int t; cin >> t;
  /*while (t--)*/ solve();
}
0