提出 #67725061


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18;

class Solution {
    int H, W;
    vector<vector<ll>> A;
    vector<ll> P, dp, ndp;

    bool check(ll x) {
        dp.assign(W+1, -INF);
        ndp.assign(W+1, -INF);
        dp[1] = x;
        for (int i = 1; i <= H; ++i) {
            fill(ndp.begin(), ndp.end(), -INF);
            for (int j = 1; j <= W; ++j) {
                ll prev = -INF;
                if (i == 1 && j == 1) prev = dp[1];
                else {
                    if (i > 1) prev = max(prev, dp[j]);
                    if (j > 1) prev = max(prev, ndp[j-1]);
                }
                if (prev < 0) continue;
                ll now = prev + A[i-1][j-1] - P[i+j-1];
                if (now >= 0) ndp[j] = now;
            }
            dp.swap(ndp);
        }
        return dp[W] >= 0;
    }

    ll binary() {
        ll lo = 0, hi = (ll)1e15;
        while (lo < hi) {
            ll mid = lo + (hi - lo) / 2;
            if (check(mid)) hi = mid;
            else lo = mid + 1;
        }
        return lo;
    }

public:
    void solve() {
        cin >> H >> W;
        A.assign(H, vector<ll>(W));
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                cin >> A[i][j];
        P.assign(H+W, 0);
        for (int k = 1; k <= H+W-1; ++k)
            cin >> P[k];
        cout << binary() << "\n";
    }
};

int main(){
    Solution* s = new Solution();
    s->solve();
    return 0;
}

提出情報

提出日時
問題 E - Hungry Takahashi
ユーザ Naman____17
言語 C++ 17 (Clang 16.0.6)
得点 450
コード長 1569 Byte
結果 AC
実行時間 142 ms
メモリ 16060 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 46
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3544 KiB
00_sample_01.txt AC 1 ms 3416 KiB
00_sample_02.txt AC 1 ms 3460 KiB
01_random_00.txt AC 134 ms 9708 KiB
01_random_01.txt AC 119 ms 9792 KiB
01_random_02.txt AC 119 ms 9740 KiB
01_random_03.txt AC 99 ms 9748 KiB
01_random_04.txt AC 77 ms 5524 KiB
01_random_05.txt AC 81 ms 5540 KiB
01_random_06.txt AC 68 ms 5596 KiB
01_random_07.txt AC 60 ms 5740 KiB
01_random_08.txt AC 77 ms 5068 KiB
01_random_09.txt AC 77 ms 5160 KiB
01_random_10.txt AC 62 ms 5132 KiB
01_random_11.txt AC 63 ms 5136 KiB
01_random_12.txt AC 76 ms 5160 KiB
01_random_13.txt AC 71 ms 5184 KiB
01_random_14.txt AC 61 ms 5152 KiB
01_random_15.txt AC 57 ms 5068 KiB
01_random_16.txt AC 70 ms 5700 KiB
01_random_17.txt AC 72 ms 5508 KiB
01_random_18.txt AC 57 ms 5608 KiB
01_random_19.txt AC 52 ms 5424 KiB
01_random_20.txt AC 101 ms 9700 KiB
01_random_21.txt AC 96 ms 9824 KiB
01_random_22.txt AC 87 ms 9824 KiB
01_random_23.txt AC 80 ms 9780 KiB
01_random_24.txt AC 134 ms 15892 KiB
01_random_25.txt AC 119 ms 16060 KiB
01_random_26.txt AC 119 ms 15976 KiB
01_random_27.txt AC 105 ms 16040 KiB
02_random2_00.txt AC 45 ms 5116 KiB
02_random2_01.txt AC 51 ms 5008 KiB
02_random2_02.txt AC 59 ms 5116 KiB
02_random2_03.txt AC 77 ms 5100 KiB
02_random2_04.txt AC 76 ms 5088 KiB
02_random2_05.txt AC 77 ms 5160 KiB
03_handmade_00.txt AC 1 ms 3452 KiB
03_handmade_01.txt AC 1 ms 3492 KiB
03_handmade_02.txt AC 1 ms 3444 KiB
03_handmade_03.txt AC 45 ms 5132 KiB
03_handmade_04.txt AC 80 ms 5100 KiB
03_handmade_05.txt AC 80 ms 5136 KiB
03_handmade_06.txt AC 106 ms 9680 KiB
03_handmade_07.txt AC 107 ms 9712 KiB
03_handmade_08.txt AC 142 ms 9708 KiB