結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー titiatitia
提出日時 2022-10-14 22:07:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 96,272 KB
最終ジャッジ日時 2023-09-08 21:49:18
合計ジャッジ時間 24,023 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,216 KB
testcase_01 AC 72 ms
71,324 KB
testcase_02 AC 72 ms
71,384 KB
testcase_03 AC 72 ms
71,256 KB
testcase_04 AC 562 ms
91,224 KB
testcase_05 AC 472 ms
89,780 KB
testcase_06 AC 136 ms
78,428 KB
testcase_07 AC 150 ms
78,816 KB
testcase_08 AC 454 ms
91,240 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 401 ms
88,240 KB
testcase_12 WA -
testcase_13 AC 244 ms
87,812 KB
testcase_14 WA -
testcase_15 AC 313 ms
86,448 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 260 ms
87,932 KB
testcase_19 AC 604 ms
94,188 KB
testcase_20 AC 178 ms
81,120 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 434 ms
89,528 KB
testcase_24 AC 678 ms
95,576 KB
testcase_25 WA -
testcase_26 AC 646 ms
96,052 KB
testcase_27 WA -
testcase_28 AC 659 ms
96,044 KB
testcase_29 WA -
testcase_30 AC 648 ms
95,816 KB
testcase_31 WA -
testcase_32 AC 671 ms
94,960 KB
testcase_33 AC 680 ms
96,132 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 185 ms
90,900 KB
testcase_47 AC 183 ms
90,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
H=list(map(int,input().split()))

E=[tuple(map(int,input().split())) for i in range(M)]

DP=[-1<<60]*N 
DP2=[-1<<60]*N # 次に下りのみ

DP[0]=0

E.sort()

for x,y in E:
    x-=1
    y-=1

    if H[x]<H[y]:
        DP2[y]=max(DP2[y],DP[x]+(H[y]-H[x]))
    else:
        DP[y]=max(DP[y],DP[x])
        DP2[y]=max(DP2[y],DP2[x])

ANS=max(DP[N-1],DP2[N-1])

if ANS<0:
    ANS=-1

DP=[-1<<60]*N 
DP2=[-1<<60]*N # 次に下りのみ

DP[N-1]=0

E.sort(reverse=True)

for x,y in E:
    x-=1
    y-=1
    x,y=y,x

    #print(x,y)

    if H[x]<H[y]:
        DP2[y]=max(DP2[y],DP[x]+(H[y]-H[x]))
    else:
        DP[y]=max(DP[y],DP[x])
        DP2[y]=max(DP2[y],DP2[x])

    #print(DP[x],DP2[x],DP[y],DP2[y])

ANS2=max(DP[0],DP2[0])

if ANS2<0:
    ANS2=-1

print(ANS)
print(ANS2)
0