結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー 👑 KazunKazun
提出日時 2022-10-09 20:09:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 86,616 KB
実行使用メモリ 125,924 KB
最終ジャッジ日時 2023-09-08 20:39:44
合計ジャッジ時間 18,785 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,204 KB
testcase_01 AC 70 ms
71,044 KB
testcase_02 AC 71 ms
71,068 KB
testcase_03 AC 71 ms
71,088 KB
testcase_04 AC 376 ms
102,868 KB
testcase_05 AC 308 ms
97,132 KB
testcase_06 AC 164 ms
83,004 KB
testcase_07 AC 176 ms
85,760 KB
testcase_08 AC 368 ms
110,180 KB
testcase_09 AC 351 ms
94,484 KB
testcase_10 AC 264 ms
83,712 KB
testcase_11 AC 297 ms
98,892 KB
testcase_12 AC 271 ms
90,292 KB
testcase_13 AC 266 ms
102,592 KB
testcase_14 AC 384 ms
88,000 KB
testcase_15 AC 284 ms
101,836 KB
testcase_16 AC 401 ms
88,596 KB
testcase_17 AC 212 ms
95,920 KB
testcase_18 AC 282 ms
102,856 KB
testcase_19 AC 431 ms
109,080 KB
testcase_20 AC 204 ms
86,664 KB
testcase_21 AC 274 ms
91,412 KB
testcase_22 AC 396 ms
89,216 KB
testcase_23 AC 357 ms
104,964 KB
testcase_24 AC 469 ms
114,312 KB
testcase_25 AC 476 ms
114,260 KB
testcase_26 AC 464 ms
114,016 KB
testcase_27 AC 463 ms
114,208 KB
testcase_28 AC 461 ms
114,184 KB
testcase_29 AC 457 ms
114,264 KB
testcase_30 AC 457 ms
114,380 KB
testcase_31 AC 458 ms
114,144 KB
testcase_32 AC 457 ms
114,164 KB
testcase_33 AC 454 ms
114,040 KB
testcase_34 AC 412 ms
90,100 KB
testcase_35 AC 335 ms
88,304 KB
testcase_36 AC 336 ms
88,428 KB
testcase_37 AC 308 ms
87,616 KB
testcase_38 AC 392 ms
89,788 KB
testcase_39 AC 241 ms
86,440 KB
testcase_40 AC 238 ms
86,644 KB
testcase_41 AC 241 ms
86,892 KB
testcase_42 AC 235 ms
86,368 KB
testcase_43 AC 241 ms
86,636 KB
testcase_44 AC 285 ms
125,504 KB
testcase_45 AC 284 ms
125,924 KB
testcase_46 AC 263 ms
120,588 KB
testcase_47 AC 261 ms
115,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N,M=map(int,input().split())
    H=[-1]+list(map(int,input().split()))

    S=[[] for _ in range(N+1)]
    T=[[] for _ in range(N+1)]

    for j in range(M):
        x,y=map(int,input().split())
        S[y].append(x)
        T[x].append(y)

    inf=float("inf")

    # チェリーちゃん
    DP_c=[[-inf,-inf] for _ in range(N+1)]
    DP_c[1][0]=0

    for b in range(1,N+1):
        for a in S[b]:
            if H[a]>H[b]:
                DP_c[b][0]=max(DP_c[b][0], max(DP_c[a]))
            else:
                DP_c[b][1]=max(DP_c[b][1], DP_c[a][0]+(H[b]-H[a]))

    # ゼルコバ君
    DP_z=[[-inf,-inf] for _ in range(N+1)]
    DP_z[N][0]=0

    for b in range(N,0,-1):
        for a in T[b]:
            if H[a]>H[b]:
                DP_z[b][0]=max(DP_z[b][0], max(DP_z[a]))
            else:
                DP_z[b][1]=max(DP_z[b][1], DP_z[a][0]+(H[b]-H[a]))


    ans_c=max(DP_c[N]) if max(DP_c[N])>-inf else -1
    ans_z=max(DP_z[1]) if max(DP_z[1])>-inf else -1

    print(ans_c, ans_z, sep="\n")

#==================================================
solve()
0