結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー ニックネームニックネーム
提出日時 2022-10-14 21:54:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 980 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 36,356 KB
最終ジャッジ日時 2023-09-08 20:58:01
合計ジャッジ時間 30,545 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,244 KB
testcase_01 AC 15 ms
8,240 KB
testcase_02 AC 16 ms
8,160 KB
testcase_03 AC 16 ms
7,856 KB
testcase_04 AC 800 ms
28,232 KB
testcase_05 AC 641 ms
24,304 KB
testcase_06 AC 95 ms
11,832 KB
testcase_07 AC 125 ms
12,844 KB
testcase_08 AC 650 ms
30,728 KB
testcase_09 AC 643 ms
23,312 KB
testcase_10 AC 532 ms
16,428 KB
testcase_11 AC 502 ms
24,492 KB
testcase_12 AC 440 ms
19,036 KB
testcase_13 AC 337 ms
24,656 KB
testcase_14 AC 449 ms
17,988 KB
testcase_15 AC 399 ms
24,688 KB
testcase_16 AC 513 ms
18,900 KB
testcase_17 AC 185 ms
21,400 KB
testcase_18 AC 359 ms
24,868 KB
testcase_19 AC 869 ms
32,236 KB
testcase_20 AC 176 ms
13,988 KB
testcase_21 AC 402 ms
18,928 KB
testcase_22 AC 485 ms
18,532 KB
testcase_23 AC 622 ms
27,952 KB
testcase_24 AC 980 ms
36,212 KB
testcase_25 AC 916 ms
36,356 KB
testcase_26 AC 905 ms
36,228 KB
testcase_27 AC 896 ms
36,212 KB
testcase_28 AC 913 ms
36,156 KB
testcase_29 AC 914 ms
36,308 KB
testcase_30 AC 915 ms
36,224 KB
testcase_31 AC 920 ms
36,236 KB
testcase_32 AC 924 ms
36,160 KB
testcase_33 AC 917 ms
36,156 KB
testcase_34 AC 780 ms
23,036 KB
testcase_35 AC 783 ms
20,680 KB
testcase_36 AC 752 ms
20,596 KB
testcase_37 AC 756 ms
19,844 KB
testcase_38 AC 792 ms
21,944 KB
testcase_39 AC 709 ms
17,248 KB
testcase_40 AC 732 ms
16,992 KB
testcase_41 AC 727 ms
17,204 KB
testcase_42 AC 714 ms
17,260 KB
testcase_43 AC 745 ms
17,228 KB
testcase_44 AC 558 ms
34,636 KB
testcase_45 AC 548 ms
34,560 KB
testcase_46 AC 492 ms
33,000 KB
testcase_47 AC 496 ms
32,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().split())
    adj[x-1].append(y-1); adj[y-1].append(x-1)
dp10 = [0]+[-1]*(n-1); dp11 = [-1]*n
dp20 = [-1]*(n-1)+[0]; dp21 = [-1]*n
for i in range(n):
    for j in adj[i]:
        if j < i: continue
        if h[j]-h[i] < 0: dp10[j] = max(dp10[j], dp10[i], dp11[i])
        elif dp10[i] > -1: dp11[j] = max(dp11[j], dp10[i]+h[j]-h[i])
for i in range(n-1, -1, -1):
    for j in adj[i]:
        if j > i: continue
        if h[j]-h[i] < 0: dp20[j] = max(dp20[j], dp20[i], dp21[i])
        elif dp20[i] > -1: dp21[j] = max(dp21[j], dp20[i]+h[j]-h[i])
print(max(dp10[-1], dp11[-1])); print(max(dp20[0], dp21[0]))
0