結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー lloyzlloyz
提出日時 2022-10-15 14:00:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 132,948 KB
最終ジャッジ日時 2023-09-09 02:34:30
合計ジャッジ時間 15,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,316 KB
testcase_01 AC 90 ms
71,672 KB
testcase_02 AC 90 ms
71,652 KB
testcase_03 AC 90 ms
71,704 KB
testcase_04 AC 299 ms
114,104 KB
testcase_05 AC 275 ms
104,992 KB
testcase_06 AC 144 ms
81,820 KB
testcase_07 AC 148 ms
83,132 KB
testcase_08 AC 286 ms
120,084 KB
testcase_09 AC 288 ms
102,264 KB
testcase_10 AC 236 ms
88,388 KB
testcase_11 AC 240 ms
105,020 KB
testcase_12 AC 225 ms
95,248 KB
testcase_13 AC 209 ms
106,096 KB
testcase_14 AC 244 ms
91,776 KB
testcase_15 AC 225 ms
106,272 KB
testcase_16 AC 259 ms
93,024 KB
testcase_17 AC 181 ms
98,800 KB
testcase_18 AC 213 ms
105,832 KB
testcase_19 AC 325 ms
122,604 KB
testcase_20 AC 164 ms
89,744 KB
testcase_21 AC 213 ms
96,624 KB
testcase_22 AC 268 ms
92,692 KB
testcase_23 AC 277 ms
113,732 KB
testcase_24 AC 349 ms
128,504 KB
testcase_25 AC 328 ms
128,704 KB
testcase_26 AC 331 ms
128,732 KB
testcase_27 AC 347 ms
129,656 KB
testcase_28 AC 338 ms
129,684 KB
testcase_29 AC 346 ms
129,360 KB
testcase_30 AC 335 ms
129,080 KB
testcase_31 AC 335 ms
129,380 KB
testcase_32 AC 353 ms
129,908 KB
testcase_33 AC 358 ms
129,852 KB
testcase_34 AC 317 ms
95,996 KB
testcase_35 AC 305 ms
94,048 KB
testcase_36 AC 296 ms
93,928 KB
testcase_37 AC 282 ms
93,696 KB
testcase_38 AC 316 ms
95,376 KB
testcase_39 AC 243 ms
92,384 KB
testcase_40 AC 240 ms
92,036 KB
testcase_41 AC 240 ms
91,892 KB
testcase_42 AC 244 ms
92,088 KB
testcase_43 AC 246 ms
91,960 KB
testcase_44 AC 268 ms
132,948 KB
testcase_45 AC 264 ms
132,628 KB
testcase_46 AC 256 ms
132,460 KB
testcase_47 AC 247 ms
132,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    G = [defaultdict(list), defaultdict(list)]
    for _ in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        G[0][x].append((y, max(H[y] - H[x], 0)))
        G[1][y].append((x, max(H[x] - H[y], 0)))

    DP = [[[-1, -1] for _ in range(n)] for _ in range(2)]
    DP[0][0][0] = 0
    for i in range(n - 1):
        for j in range(2):
            if DP[0][i][j] != -1:
                for k, d in G[0][i]:
                    if d > 0:
                        if j == 0:
                            DP[0][k][1] = max(DP[0][k][1], DP[0][i][j] + d)
                    else:
                        DP[0][k][0] = max(DP[0][k][0], DP[0][i][j])
    print(max(DP[0][n - 1]))
    DP[1][n - 1][0] = 0
    for i in range(n - 1, 0, -1):
        for j in range(2):
            if DP[1][i][j] != -1:
                for k, d in G[1][i]:
                    if d > 0:
                        if j == 0:
                            DP[1][k][1] = max(DP[1][k][1], DP[1][i][j] + d)
                    else:
                        DP[1][k][0] = max(DP[1][k][0], DP[1][i][j])
    print(max(DP[1][0]))

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