結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー rlangevinrlangevin
提出日時 2023-01-15 10:41:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 430 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 103,184 KB
最終ジャッジ日時 2023-08-27 18:27:29
合計ジャッジ時間 18,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,004 KB
testcase_01 AC 70 ms
71,268 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 71 ms
71,160 KB
testcase_04 AC 383 ms
93,312 KB
testcase_05 AC 302 ms
90,296 KB
testcase_06 AC 158 ms
81,584 KB
testcase_07 AC 162 ms
82,784 KB
testcase_08 AC 351 ms
97,232 KB
testcase_09 AC 298 ms
89,376 KB
testcase_10 AC 211 ms
82,428 KB
testcase_11 AC 283 ms
91,544 KB
testcase_12 AC 237 ms
85,888 KB
testcase_13 AC 245 ms
92,700 KB
testcase_14 AC 226 ms
83,100 KB
testcase_15 AC 262 ms
91,444 KB
testcase_16 AC 236 ms
83,632 KB
testcase_17 AC 187 ms
90,780 KB
testcase_18 AC 249 ms
93,076 KB
testcase_19 AC 392 ms
96,988 KB
testcase_20 AC 180 ms
83,564 KB
testcase_21 AC 239 ms
86,552 KB
testcase_22 AC 230 ms
84,056 KB
testcase_23 AC 332 ms
94,844 KB
testcase_24 AC 412 ms
99,796 KB
testcase_25 AC 421 ms
99,572 KB
testcase_26 AC 421 ms
99,852 KB
testcase_27 AC 414 ms
99,808 KB
testcase_28 AC 413 ms
99,828 KB
testcase_29 AC 411 ms
99,544 KB
testcase_30 AC 415 ms
99,812 KB
testcase_31 AC 410 ms
99,812 KB
testcase_32 AC 416 ms
99,692 KB
testcase_33 AC 430 ms
99,744 KB
testcase_34 AC 268 ms
85,844 KB
testcase_35 AC 260 ms
86,276 KB
testcase_36 AC 254 ms
86,784 KB
testcase_37 AC 243 ms
86,328 KB
testcase_38 AC 267 ms
86,276 KB
testcase_39 AC 205 ms
83,596 KB
testcase_40 AC 205 ms
83,676 KB
testcase_41 AC 204 ms
83,612 KB
testcase_42 AC 209 ms
85,868 KB
testcase_43 AC 206 ms
85,812 KB
testcase_44 AC 218 ms
103,016 KB
testcase_45 AC 217 ms
103,184 KB
testcase_46 AC 206 ms
100,128 KB
testcase_47 AC 206 ms
100,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def calc(h, G):
    inf = 10 ** 18
    dp0 = [-inf] * N
    dp1 = [-inf] * N
    dp0[0] = 0
    for i in range(N):
        for u in G[i]:
            if h[u] > h[i]:
                dp1[u] = max(dp1[u], dp0[i] + h[u] - h[i])
            else:
                dp0[u] = max(dp0[u], dp0[i], dp1[i])
    v = max(dp0[-1], dp1[-1])
    if v < 0:
        return -1
    else:
        return v           
    

N, M = map(int, input().split())
H = list(map(int, input().split()))
G1 = [[] for i in range(N)]
G2 = [[] for i in range(N)]
for i in range(M):
    X, Y = map(int, input().split())
    G1[X - 1].append(Y - 1)
    G2[N - Y].append(N - X)
    
ans1= calc(H, G1)
H.reverse()
ans2 = calc(H, G2)
print(ans1)
print(ans2)
0