提出 #67772349


ソースコード 拡げる

H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(map(int, input().split())))

P = list(map(int, input().split()))

# S[i][j] = (x, y) ; x -> 過去のお金のマイナス値の最大 (絶対値として最小),
#                    y -> 今の所持金
S = [[None] * W for _ in range(H)]
S[0][0] = (A[0][0] - P[0], A[0][0] - P[0])

for k in range(1, H+W-1): # 1 日目から H+W-2 日目まで
    for hi in range(1, k+1): # hi, wi の全範囲
        if hi > H:
            continue

        wi = k + 1 - hi
        if wi > W:
            continue

        # 右へ行く
        if wi != W: # 端っこでなければ
            x, y = S[hi-1][wi-1] # 今の (x, y)
            y += (A[hi-1][wi] - P[k]) # 右に行ったときの, 現在のお金
            if x > y: # お金が, 過去の金額より小さくなっていたら, 値を更新
                x = y

            if S[hi-1][wi] == None: # まだ訪問してなければ
                S[hi-1][wi] = (x, y) # そのまま書き込む
            else: # 訪問していれば
                x_cur, y_cur = S[hi-1][wi] # 今の値
                if x_cur < x: # 今の値よりも, x が大きい (マイナスなら, 絶対として小さい) なら
                    S[hi-1][wi] = (x, y) # 値を更新
                
        # 下へ行く (右へ行く時と同様)
        if hi != H:
            x, y = S[hi-1][wi-1]
            y += (A[hi][wi-1] - P[k])
            if x > y:
                x = y

            if S[hi][wi-1] == None:
                S[hi][wi-1] = (x, y)
            else:
                x_cur, y_cur = S[hi][wi-1]
                if x_cur < x:
                    S[hi][wi-1] = (x, y)

# print(S)
x, _ = S[H-1][W-1] # 最終地点で, お金の値をチェック
if x > 0: # 正の値なら, 過去に一度も負になったことがないので, ゼロにする
    x = 0

print(-x) # 符号をつけて出力

提出情報

提出日時
問題 E - Hungry Takahashi
ユーザ satomshr
言語 Python (PyPy 3.10-v7.3.12)
得点 0
コード長 1999 Byte
結果 WA
実行時間 3318 ms
メモリ 161724 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 450
結果
AC × 3
AC × 26
WA × 5
TLE × 15
セット名 テストケース
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 62 ms 75920 KiB
00_sample_01.txt AC 62 ms 75840 KiB
00_sample_02.txt AC 63 ms 75964 KiB
01_random_00.txt TLE 3316 ms 118204 KiB
01_random_01.txt TLE 3316 ms 117212 KiB
01_random_02.txt TLE 3316 ms 117968 KiB
01_random_03.txt TLE 3316 ms 124116 KiB
01_random_04.txt WA 1129 ms 94400 KiB
01_random_05.txt AC 1126 ms 95672 KiB
01_random_06.txt AC 1157 ms 91688 KiB
01_random_07.txt WA 1151 ms 92048 KiB
01_random_08.txt AC 105 ms 84724 KiB
01_random_09.txt AC 101 ms 84164 KiB
01_random_10.txt WA 118 ms 86428 KiB
01_random_11.txt AC 110 ms 86060 KiB
01_random_12.txt AC 105 ms 85968 KiB
01_random_13.txt AC 101 ms 85912 KiB
01_random_14.txt WA 117 ms 86316 KiB
01_random_15.txt AC 109 ms 86316 KiB
01_random_16.txt AC 171 ms 85384 KiB
01_random_17.txt AC 165 ms 85504 KiB
01_random_18.txt WA 183 ms 88296 KiB
01_random_19.txt AC 173 ms 87952 KiB
01_random_20.txt TLE 3318 ms 118340 KiB
01_random_21.txt TLE 3316 ms 117856 KiB
01_random_22.txt TLE 3316 ms 118644 KiB
01_random_23.txt TLE 3316 ms 118760 KiB
01_random_24.txt TLE 3318 ms 161724 KiB
01_random_25.txt TLE 3317 ms 136464 KiB
01_random_26.txt TLE 3317 ms 136636 KiB
01_random_27.txt TLE 3318 ms 140908 KiB
02_random2_00.txt AC 106 ms 89060 KiB
02_random2_01.txt AC 107 ms 87980 KiB
02_random2_02.txt AC 105 ms 86716 KiB
02_random2_03.txt AC 100 ms 85856 KiB
02_random2_04.txt AC 100 ms 85680 KiB
02_random2_05.txt AC 100 ms 85712 KiB
03_handmade_00.txt AC 60 ms 76000 KiB
03_handmade_01.txt AC 60 ms 75940 KiB
03_handmade_02.txt AC 61 ms 76064 KiB
03_handmade_03.txt AC 97 ms 83356 KiB
03_handmade_04.txt AC 103 ms 85660 KiB
03_handmade_05.txt AC 101 ms 85636 KiB
03_handmade_06.txt TLE 3316 ms 122776 KiB
03_handmade_07.txt TLE 3316 ms 118564 KiB
03_handmade_08.txt TLE 3316 ms 119896 KiB