結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー AkariAkari
提出日時 2022-10-14 22:20:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 116,688 KB
最終ジャッジ日時 2023-09-08 22:17:40
合計ジャッジ時間 13,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,288 KB
testcase_01 AC 73 ms
70,936 KB
testcase_02 AC 74 ms
71,084 KB
testcase_03 AC 71 ms
71,168 KB
testcase_04 AC 297 ms
103,352 KB
testcase_05 AC 243 ms
96,392 KB
testcase_06 AC 120 ms
79,528 KB
testcase_07 AC 140 ms
82,924 KB
testcase_08 AC 301 ms
111,012 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 226 ms
94,588 KB
testcase_12 WA -
testcase_13 AC 203 ms
96,696 KB
testcase_14 WA -
testcase_15 AC 233 ms
102,136 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 209 ms
97,120 KB
testcase_19 AC 337 ms
109,464 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 292 ms
102,444 KB
testcase_24 AC 380 ms
114,484 KB
testcase_25 WA -
testcase_26 AC 352 ms
114,568 KB
testcase_27 WA -
testcase_28 AC 371 ms
114,332 KB
testcase_29 AC 368 ms
114,768 KB
testcase_30 AC 374 ms
114,492 KB
testcase_31 AC 357 ms
114,552 KB
testcase_32 AC 360 ms
114,720 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 168 ms
83,812 KB
testcase_40 AC 171 ms
83,992 KB
testcase_41 AC 173 ms
83,772 KB
testcase_42 AC 180 ms
83,544 KB
testcase_43 AC 175 ms
83,416 KB
testcase_44 AC 208 ms
114,368 KB
testcase_45 AC 205 ms
113,516 KB
testcase_46 AC 209 ms
115,304 KB
testcase_47 AC 207 ms
116,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys



def solve(H, g):
    n = len(H)
    dp = [[-1] * 2 for _ in range(n)]
    dp[0] = [0, 0]
    for x in range(n):
        hx = H[x]
        for y in g[x]:
            hy = H[y]
            up = 1 if hy > hx else 0
            d = max(0, hy - hx)
            for i in range(2):
                if dp[x][i] == -1: continue
                if i == 1 and up: continue
                dp[y][up] = max(dp[y][up], dp[x][i] + d)
    return max(dp[-1])




def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    g1 = [[] for _ in range(n)]
    g2 = [[] for _ in range(n)]
    n2 = n - 1
    for _ in range(m):
        x, y = map(lambda x: int(x) - 1, input().split())
        g1[x].append(y)
        g2[n2 - y].append(n2 - x)
    print(solve(H, g1))
    print(solve(H[::-1], g1))



if __name__ == '__main__':
    main()
0