結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー milanis48663220milanis48663220
提出日時 2022-05-20 22:12:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,386 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 125,132 KB
実行使用メモリ 19,064 KB
最終ジャッジ日時 2023-10-20 12:55:13
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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 45 ms
19,064 KB
testcase_08 AC 56 ms
19,064 KB
testcase_09 AC 57 ms
19,064 KB
testcase_10 AC 57 ms
19,064 KB
testcase_11 AC 56 ms
18,800 KB
testcase_12 AC 50 ms
19,064 KB
testcase_13 AC 50 ms
19,064 KB
testcase_14 AC 50 ms
19,064 KB
testcase_15 AC 50 ms
19,064 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 53 ms
19,064 KB
testcase_21 AC 52 ms
18,800 KB
testcase_22 AC 47 ms
19,064 KB
testcase_23 AC 46 ms
19,064 KB
testcase_24 AC 47 ms
19,064 KB
testcase_25 AC 55 ms
18,272 KB
testcase_26 AC 58 ms
19,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const ll inf = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, w; cin >> h >> w;
    auto a = vec2d(h, w, 0ll);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    auto dp = vec3d(h, w, 2, -inf);
    dp[0][0][0] = a[0][0];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 2; k++){
                if(i != h-1 && a[i+1][j] < dp[i][j][k]){
                    chmax(dp[i+1][j][k], dp[i][j][k]+a[i+1][j]);
                }
                if(i != h-1 && k == 0 && a[i+1][j] >= dp[i][j][k]){
                    chmax(dp[i+1][j][1], dp[i][j][k]);
                }
                if(j != w-1 && a[i][j+1] < dp[i][j][k]){
                    chmax(dp[i][j+1][k], dp[i][j][k]+a[i][j+1]);
                }
                if(j != w-1 && k == 0 && a[i][j+1] >= dp[i][j][k]){
                    chmax(dp[i][j+1][1], dp[i][j][k]);
                }
            }
        }
    }
    if(dp[h-1][w-1][0] > a[h-1][w-1] || dp[h-1][w-1][1] > a[h-1][w-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
0