結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-10-14 22:34:12
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 108,484 KB
最終ジャッジ日時 2023-09-08 22:48:47
合計ジャッジ時間 16,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,136 KB
testcase_01 AC 71 ms
71,112 KB
testcase_02 AC 69 ms
70,960 KB
testcase_03 AC 69 ms
71,148 KB
testcase_04 AC 344 ms
99,264 KB
testcase_05 AC 288 ms
94,200 KB
testcase_06 AC 166 ms
80,904 KB
testcase_07 AC 161 ms
82,564 KB
testcase_08 AC 365 ms
105,588 KB
testcase_09 AC 291 ms
92,020 KB
testcase_10 AC 218 ms
82,784 KB
testcase_11 AC 283 ms
96,508 KB
testcase_12 AC 244 ms
88,452 KB
testcase_13 AC 241 ms
93,596 KB
testcase_14 AC 229 ms
84,448 KB
testcase_15 AC 264 ms
97,920 KB
testcase_16 AC 234 ms
84,980 KB
testcase_17 AC 211 ms
95,892 KB
testcase_18 AC 247 ms
99,136 KB
testcase_19 AC 396 ms
104,496 KB
testcase_20 AC 179 ms
85,108 KB
testcase_21 AC 230 ms
89,172 KB
testcase_22 AC 240 ms
84,388 KB
testcase_23 AC 324 ms
100,948 KB
testcase_24 AC 431 ms
108,288 KB
testcase_25 AC 415 ms
108,244 KB
testcase_26 AC 422 ms
108,412 KB
testcase_27 AC 425 ms
108,484 KB
testcase_28 AC 458 ms
108,452 KB
testcase_29 AC 443 ms
108,380 KB
testcase_30 AC 436 ms
108,432 KB
testcase_31 AC 431 ms
108,264 KB
testcase_32 AC 424 ms
108,460 KB
testcase_33 AC 407 ms
108,268 KB
testcase_34 AC 277 ms
87,292 KB
testcase_35 AC 264 ms
86,812 KB
testcase_36 AC 265 ms
86,852 KB
testcase_37 AC 251 ms
86,420 KB
testcase_38 AC 286 ms
87,512 KB
testcase_39 AC 234 ms
86,492 KB
testcase_40 AC 224 ms
86,516 KB
testcase_41 AC 227 ms
86,600 KB
testcase_42 AC 223 ms
86,252 KB
testcase_43 AC 226 ms
86,688 KB
testcase_44 AC 234 ms
107,424 KB
testcase_45 AC 233 ms
107,172 KB
testcase_46 AC 226 ms
106,900 KB
testcase_47 AC 226 ms
107,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
H = list(map(int,input().split()))
e = [[] for i in range(n)]
for _ in range(m):
    x,y = map(int,input().split())
    x,y = x-1,y-1
    e[x].append(y)
    e[y].append(x)


dp = [[-1]*2 for i in range(n)]
dp[0] = [0,0]
for i in range(n):
    h = H[i]
    for nex in e[i]:
        if nex < i:
            continue
        nh = H[nex]
        if h < nh and dp[i][0] != -1:
            dp[nex][1] = max(dp[nex][1],dp[i][0]+nh-h)
        if h > nh:
            dp[nex][0] = max(dp[nex][0],max(dp[i]))

print(max(dp[-1]))
      
dp = [[-1]*2 for i in range(n)]
dp[-1] = [0,0]
for i in range(n)[::-1]:
    h = H[i]
    for nex in e[i]:
        if nex > i:
            continue
        nh = H[nex]
        if h < nh and dp[i][0] != -1:
            dp[nex][1] = max(dp[nex][1],dp[i][0]+nh-h)
        if h > nh:
            dp[nex][0] = max(dp[nex][0],max(dp[i]))

print(max(dp[0]))
      
0