Submission #67723912


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using mint=atcoder::modint998244353;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define rng(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrng(i,l,r) for(int i=(r)-1;i>=l;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()

struct fast_io{fast_io(){cin.tie(nullptr)->sync_with_stdio(false);}}_;

signed main(){
    int H,W;cin>>H>>W;

    vector<vector<int>> A(H,vector<int>(W));
    rep(i,H)rep(j,W)cin>>A[i][j];

    vector<int> P(H+W-1);
    rep(i,H+W-1)cin>>P[i];

    auto judge=[&](int x)->bool {
        vector<vector<int>> dp(H,vector<int>(W,-1e18));
        dp[0][0]=A[0][0]+x;

        rep(i,H)rep(j,W){
            if(dp[i][j]<P[i+j])continue;
            if(i==H-1&&j==W-1)return 1;
            dp[i][j]-=P[i+j];
            if(i!=H-1)dp[i+1][j]=max(dp[i+1][j],dp[i][j]+A[i+1][j]);
            if(j!=W-1)dp[i][j+1]=max(dp[i][j+1],dp[i][j]+A[i][j+1]);
        }

        return 0;
    };

    int ok=1e15,ng=-1;
    while(abs(ok-ng)>1){
        int m=(ok+ng)>>1;
        if(judge(m))ok=m;
        else ng=m;
    }

    cout<<ok<<"\n";
}

Submission Info

Submission Time
Task E - Hungry Takahashi
User nouka28
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1341 Byte
Status AC
Exec Time 483 ms
Memory 26708 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 46
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3552 KiB
00_sample_01.txt AC 1 ms 3524 KiB
00_sample_02.txt AC 1 ms 3464 KiB
01_random_00.txt AC 78 ms 9220 KiB
01_random_01.txt AC 77 ms 9316 KiB
01_random_02.txt AC 78 ms 9280 KiB
01_random_03.txt AC 63 ms 9224 KiB
01_random_04.txt AC 66 ms 6740 KiB
01_random_05.txt AC 79 ms 6672 KiB
01_random_06.txt AC 80 ms 6664 KiB
01_random_07.txt AC 66 ms 6668 KiB
01_random_08.txt AC 76 ms 6280 KiB
01_random_09.txt AC 77 ms 6188 KiB
01_random_10.txt AC 78 ms 6352 KiB
01_random_11.txt AC 77 ms 6216 KiB
01_random_12.txt AC 75 ms 6352 KiB
01_random_13.txt AC 66 ms 6244 KiB
01_random_14.txt AC 77 ms 6428 KiB
01_random_15.txt AC 67 ms 6448 KiB
01_random_16.txt AC 77 ms 7200 KiB
01_random_17.txt AC 86 ms 7340 KiB
01_random_18.txt AC 87 ms 7288 KiB
01_random_19.txt AC 67 ms 7304 KiB
01_random_20.txt AC 234 ms 14856 KiB
01_random_21.txt AC 243 ms 14856 KiB
01_random_22.txt AC 238 ms 14904 KiB
01_random_23.txt AC 235 ms 15048 KiB
01_random_24.txt AC 483 ms 26568 KiB
01_random_25.txt AC 474 ms 26708 KiB
01_random_26.txt AC 466 ms 26540 KiB
01_random_27.txt AC 463 ms 26636 KiB
02_random2_00.txt AC 70 ms 6332 KiB
02_random2_01.txt AC 71 ms 6212 KiB
02_random2_02.txt AC 73 ms 6404 KiB
02_random2_03.txt AC 75 ms 6340 KiB
02_random2_04.txt AC 74 ms 6256 KiB
02_random2_05.txt AC 74 ms 6256 KiB
03_handmade_00.txt AC 1 ms 3528 KiB
03_handmade_01.txt AC 1 ms 3500 KiB
03_handmade_02.txt AC 1 ms 3552 KiB
03_handmade_03.txt AC 70 ms 6324 KiB
03_handmade_04.txt AC 74 ms 6216 KiB
03_handmade_05.txt AC 75 ms 6328 KiB
03_handmade_06.txt AC 72 ms 9200 KiB
03_handmade_07.txt AC 73 ms 9360 KiB
03_handmade_08.txt AC 79 ms 9284 KiB