結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー erbowlerbowl
提出日時 2022-08-07 21:27:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,145 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 208,488 KB
実行使用メモリ 9,620 KB
最終ジャッジ日時 2023-10-17 16:03:38
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 61 ms
9,620 KB
testcase_08 AC 113 ms
9,620 KB
testcase_09 AC 115 ms
9,620 KB
testcase_10 AC 115 ms
9,620 KB
testcase_11 AC 112 ms
9,584 KB
testcase_12 AC 83 ms
9,620 KB
testcase_13 AC 84 ms
9,620 KB
testcase_14 AC 83 ms
9,620 KB
testcase_15 AC 83 ms
9,620 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 84 ms
9,620 KB
testcase_21 AC 83 ms
9,572 KB
testcase_22 AC 68 ms
9,620 KB
testcase_23 AC 68 ms
9,620 KB
testcase_24 AC 70 ms
9,620 KB
testcase_25 AC 104 ms
9,388 KB
testcase_26 AC 109 ms
9,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef tuple<ll,ll,ll> tll;

signed main(){
    ll h,w,y,x;
    std::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++) {
            std::cin >> a[i][j];
        }
    }
    vector<vector<ll>> b1(h,vector<ll>(w,-1));
    vector<vector<ll>> b2(h,vector<ll>(w,-1));
    b1[0][0]=a[0][0];
    for (int ii = 0; ii < w; ii++) {
        ll x,y;
        x = ii;
        y = 0;
        while(0<=x&&y<h){
            if(b1[y][x]!=-1){
                if(y+1<h){
                    if(a[y+1][x]<b1[y][x]){
                        b1[y+1][x] = max(b1[y+1][x],b1[y][x]+a[y+1][x]);
                    }else{
                        b2[y+1][x] = max(b1[y+1][x],b1[y][x]);
                    }
                }
                if(x+1<w){
                    if(a[y][x+1]<b1[y][x]){
                        b1[y][x+1] = max(b1[y][x+1],b1[y][x]+a[y][x+1]);
                    }else{
                        b2[y][x+1] = max(b1[y][x+1],b1[y][x]);
                    }
                }
            }
            if(b2[y][x]!=-1){
                if(y+1<h){
                    if(a[y+1][x]<b2[y][x]){
                        b2[y+1][x] = max(b2[y+1][x],b2[y][x]+a[y+1][x]);
                    }
                }
                if(x+1<w){
                    if(a[y][x+1]<b2[y][x]){
                        b2[y][x+1] = max(b2[y][x+1],b2[y][x]+a[y][x+1]);
                    }
                }
            }
            // std::cout << x<<" "<<y<<" "<<b1[y][x]<<" "<<b2[y][x] << std::endl;
            x--;
            y++;
        }
    }
    for (int ii = 1; ii < h; ii++) {
        ll x,y;
        x = w-1;
        y = ii;
        while(0<=x&&y<h){
            if(b1[y][x]!=-1){
                if(y+1<h){
                    if(a[y+1][x]<b1[y][x]){
                        b1[y+1][x] = max(b1[y+1][x],b1[y][x]+a[y+1][x]);
                    }else{
                        b2[y+1][x] = max(b1[y+1][x],b1[y][x]);
                    }
                }
                if(x+1<w){
                    if(a[y][x+1]<b1[y][x]){
                        b1[y][x+1] = max(b1[y][x+1],b1[y][x]+a[y][x+1]);
                    }else{
                        b2[y][x+1] = max(b1[y][x+1],b1[y][x]);
                    }
                }
            }
            if(b2[y][x]!=-1){
                if(y+1<h){
                    if(a[y+1][x]<b2[y][x]){
                        b2[y+1][x] = max(b2[y+1][x],b2[y][x]+a[y+1][x]);
                    }
                }
                if(x+1<w){
                    if(a[y][x+1]<b2[y][x]){
                        b2[y][x+1] = max(b2[y][x+1],b2[y][x]+a[y][x+1]);
                    }
                }
            }
            // std::cout << x<<" "<<y<<" "<<b1[y][x]<<" "<<b2[y][x] << std::endl;
            x--;
            y++;
        }
    }
    if((b1[h-1][w-1]!=-1)||(b2[h-1][w-1]!=-1&&b2[h-1][w-1]>a[h-1][w-1])){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}
0