結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 蜜蜂蜜蜂
提出日時 2022-05-06 01:30:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,842 bytes
コンパイル時間 3,950 ms
コンパイル使用メモリ 228,816 KB
実行使用メモリ 9,356 KB
最終ジャッジ日時 2023-09-18 11:50:28
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 25 ms
9,268 KB
testcase_08 AC 37 ms
9,356 KB
testcase_09 AC 38 ms
9,220 KB
testcase_10 AC 38 ms
8,920 KB
testcase_11 AC 37 ms
8,884 KB
testcase_12 AC 31 ms
8,836 KB
testcase_13 AC 30 ms
8,840 KB
testcase_14 AC 31 ms
9,192 KB
testcase_15 AC 31 ms
8,876 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 31 ms
8,880 KB
testcase_21 AC 31 ms
8,836 KB
testcase_22 AC 26 ms
9,212 KB
testcase_23 AC 26 ms
8,952 KB
testcase_24 AC 26 ms
9,196 KB
testcase_25 AC 34 ms
8,876 KB
testcase_26 AC 37 ms
9,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h,w;
  cin>>h>>w;

  vvll a(h,vll(w,0)),dp1(h,vll(w,0)),dp2(h,vll(w,0));

  rep(i,0,h){
    rep(j,0,w){
      cin>>a[i][j];
    }
  }

  dp1[0][0]=a[0][0];

  rep(i,0,h){
    rep(j,0,w){
      if(i<h-1){
        int ni=i+1,nj=j;
        if(dp1[i][j]>a[ni][nj]){
          dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]);
        }
        else if(ni+nj!=h+w-2){
          dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]);
        }

        if(dp2[i][j]>a[ni][nj]){
          dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]);
        }
      }

      if(j<w-1){
        int ni=i,nj=j+1;
        if(dp1[i][j]>a[ni][nj]){
          dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]);
        }
        else if(ni+nj!=h+w-2){
          dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]);
        }

        if(dp2[i][j]>a[ni][nj]){
          dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]);
        }
      }
    }
  }

  if(dp1[h-1][w-1]==0&&dp2[h-1][w-1]==0){
    cout<<"No\n";
  }
  else{
    cout<<"Yes\n";
  }
}
0