結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー titiatitia
提出日時 2022-10-14 22:10:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 97,104 KB
最終ジャッジ日時 2023-09-08 21:54:00
合計ジャッジ時間 24,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,284 KB
testcase_01 AC 78 ms
71,300 KB
testcase_02 AC 77 ms
71,236 KB
testcase_03 AC 76 ms
71,352 KB
testcase_04 AC 597 ms
92,240 KB
testcase_05 AC 500 ms
94,176 KB
testcase_06 AC 142 ms
78,260 KB
testcase_07 AC 159 ms
79,828 KB
testcase_08 AC 478 ms
92,016 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 393 ms
88,228 KB
testcase_12 WA -
testcase_13 AC 255 ms
87,596 KB
testcase_14 WA -
testcase_15 AC 306 ms
86,412 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 266 ms
87,608 KB
testcase_19 AC 638 ms
96,016 KB
testcase_20 AC 189 ms
80,744 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 475 ms
91,172 KB
testcase_24 AC 697 ms
96,220 KB
testcase_25 WA -
testcase_26 AC 702 ms
96,184 KB
testcase_27 WA -
testcase_28 AC 694 ms
96,676 KB
testcase_29 WA -
testcase_30 AC 696 ms
96,520 KB
testcase_31 WA -
testcase_32 AC 692 ms
96,596 KB
testcase_33 AC 693 ms
96,632 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 181 ms
90,800 KB
testcase_47 AC 183 ms
90,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from operator import itemgetter

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(key=itemgetter(0))

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(key=itemgetter(1),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