結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー AkariAkari
提出日時 2022-10-14 22:24:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 818 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 51,856 KB
最終ジャッジ日時 2023-09-08 22:31:42
合計ジャッジ時間 26,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 16 ms
7,856 KB
testcase_02 AC 15 ms
7,800 KB
testcase_03 AC 16 ms
7,792 KB
testcase_04 AC 590 ms
37,752 KB
testcase_05 AC 439 ms
30,292 KB
testcase_06 AC 83 ms
13,976 KB
testcase_07 AC 103 ms
15,360 KB
testcase_08 AC 621 ms
44,244 KB
testcase_09 AC 466 ms
27,592 KB
testcase_10 AC 378 ms
17,224 KB
testcase_11 AC 428 ms
32,176 KB
testcase_12 AC 324 ms
23,264 KB
testcase_13 AC 364 ms
34,536 KB
testcase_14 AC 324 ms
19,520 KB
testcase_15 AC 396 ms
33,960 KB
testcase_16 AC 356 ms
20,424 KB
testcase_17 AC 242 ms
30,528 KB
testcase_18 AC 378 ms
34,968 KB
testcase_19 AC 731 ms
44,236 KB
testcase_20 AC 144 ms
16,880 KB
testcase_21 AC 316 ms
23,192 KB
testcase_22 AC 341 ms
20,036 KB
testcase_23 AC 562 ms
38,900 KB
testcase_24 AC 808 ms
49,788 KB
testcase_25 AC 816 ms
49,640 KB
testcase_26 AC 818 ms
49,584 KB
testcase_27 AC 792 ms
49,536 KB
testcase_28 AC 795 ms
49,652 KB
testcase_29 AC 817 ms
49,676 KB
testcase_30 AC 818 ms
49,668 KB
testcase_31 AC 806 ms
49,720 KB
testcase_32 AC 809 ms
49,668 KB
testcase_33 AC 798 ms
49,580 KB
testcase_34 AC 559 ms
23,956 KB
testcase_35 AC 561 ms
22,052 KB
testcase_36 AC 551 ms
21,720 KB
testcase_37 AC 536 ms
20,896 KB
testcase_38 AC 565 ms
23,304 KB
testcase_39 AC 526 ms
18,468 KB
testcase_40 AC 525 ms
18,592 KB
testcase_41 AC 534 ms
18,596 KB
testcase_42 AC 528 ms
18,516 KB
testcase_43 AC 531 ms
18,556 KB
testcase_44 AC 517 ms
51,800 KB
testcase_45 AC 516 ms
51,856 KB
testcase_46 AC 468 ms
48,664 KB
testcase_47 AC 480 ms
48,648 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], g2))



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