結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー MazesobaMazesoba
提出日時 2022-05-20 23:45:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 3,249 bytes
コンパイル時間 4,631 ms
コンパイル使用メモリ 264,288 KB
実行使用メモリ 6,712 KB
最終ジャッジ日時 2023-10-20 14:41:44
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 58 ms
6,712 KB
testcase_08 AC 113 ms
6,712 KB
testcase_09 AC 116 ms
6,712 KB
testcase_10 AC 114 ms
6,712 KB
testcase_11 AC 113 ms
6,684 KB
testcase_12 AC 83 ms
6,712 KB
testcase_13 AC 82 ms
6,712 KB
testcase_14 AC 83 ms
6,712 KB
testcase_15 AC 83 ms
6,712 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
6,712 KB
testcase_21 AC 82 ms
6,700 KB
testcase_22 AC 67 ms
6,712 KB
testcase_23 AC 67 ms
6,712 KB
testcase_24 AC 67 ms
6,712 KB
testcase_25 AC 103 ms
6,596 KB
testcase_26 AC 107 ms
6,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

//#define DISABLE_PRINT

#if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT)

#define P(...) fprintf(stderr, __VA_ARGS__)
#define P2(fmt) fprintf(stderr, fmt)
#define LP fprintf(stderr, "L: %d\n", __LINE__)

#else

#define P(...) ((void)0)
#define P2(fmt) ((void)0)
#define LP ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using ull = unsigned long long;

int main(int, const char**)
{
    int H, W; cin >> H >> W;
    vector<vector<int>> g(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >>g[i][j];

    vector<vector<int>> v0(H, vector<int>(W));
    v0[0][0] = g[0][0];
    {
        rep(i, H) rep(j, W) {
            auto p = v0[i][j];
            if(p > 0) {
                if(i < H - 1) {
                    if(p > g[i + 1][j]) {
                        v0[i + 1][j] = p + g[i + 1][j];
                    }
                    else {
                        v0[i + 1][j] = -p;
                    }
                }

                if(j < W - 1) {
                    if(p > g[i][j + 1]) {
                        v0[i][j + 1] = max(v0[i][j + 1], p + g[i][j + 1]);
                    }
                    else {
                        if(v0[i][j + 1] > 0) continue;
                        v0[i][j + 1] = min(-p, v0[i][j + 1]);
                    }
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            P("%3d ", v0[i][j]);
        }
        P("\n");
    }

    const int INF = 1000000005;
    vector<vector<int>> v1(H, vector<int>(W, INF));
    v1[H - 1][W - 1] = g[H - 1][W - 1] + 1;

    {
        rep(ii, H) rep(jj, W) {
            auto i = H - 1 - ii;
            auto j = W - 1 - jj;
            auto p = v1[i][j];
            if(p > 0) {
                if(i > 0) {
                    if(p > g[i - 1][j]) {
                        v1[i - 1][j] = max(p - g[i - 1][j], g[i - 1][j] + 1);
                    }
                    else {
                        v1[i - 1][j] = g[i - 1][j] + 1;
                    }
                }

                if(j > 0) {
                    if(p > g[i][j - 1]) {
                        v1[i][j - 1] = min(v1[i][j - 1], p - g[i][j - 1]);
                        v1[i][j - 1] = max(v1[i][j - 1], g[i][j - 1] + 1);
                    }
                    else {
                        if(v1[i][j - 1] == INF) v1[i][j - 1] = g[i][j - 1] + 1;
                        else v1[i][j - 1] = max(v1[i][j - 1], g[i][j - 1] + 1);
                    }
                }
            }
        }
    }


    P("----\n");
    rep(i, H) {
        rep(j, W) {
            P("%3d ", v1[i][j]);
        }
        P("\n");
    }

    if(v0[H - 1][W - 1] >= v1[H - 1][W - 1]) {
LP;
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, H) rep(j, W) {
        if(v0[i][j] >= 0) continue;
        auto p = -v0[i][j];
        if(i < H - 1 && p >= v1[i + 1][j]) {
LP;
            cout << "Yes" << endl;
            return 0;
        }
        if(j < W - 1 && p >= v1[i][j + 1]) {
LP;
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}
0