結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー 👑 KazunKazun
提出日時 2022-07-28 00:58:25
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 132,052 KB
最終ジャッジ日時 2023-09-08 19:52:28
合計ジャッジ時間 21,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,328 KB
testcase_01 AC 70 ms
71,192 KB
testcase_02 AC 69 ms
71,412 KB
testcase_03 AC 70 ms
71,312 KB
testcase_04 AC 382 ms
102,876 KB
testcase_05 AC 284 ms
97,152 KB
testcase_06 AC 148 ms
83,004 KB
testcase_07 AC 154 ms
84,236 KB
testcase_08 AC 353 ms
110,200 KB
testcase_09 AC 325 ms
94,384 KB
testcase_10 AC 309 ms
84,908 KB
testcase_11 AC 279 ms
99,124 KB
testcase_12 AC 244 ms
90,460 KB
testcase_13 AC 244 ms
102,716 KB
testcase_14 AC 395 ms
89,040 KB
testcase_15 AC 262 ms
101,608 KB
testcase_16 AC 395 ms
90,052 KB
testcase_17 AC 206 ms
95,772 KB
testcase_18 AC 252 ms
102,984 KB
testcase_19 AC 376 ms
109,108 KB
testcase_20 AC 171 ms
86,692 KB
testcase_21 AC 231 ms
90,952 KB
testcase_22 AC 361 ms
89,096 KB
testcase_23 AC 336 ms
105,224 KB
testcase_24 AC 434 ms
114,208 KB
testcase_25 AC 424 ms
114,416 KB
testcase_26 AC 431 ms
114,072 KB
testcase_27 AC 420 ms
114,344 KB
testcase_28 AC 423 ms
114,364 KB
testcase_29 AC 417 ms
114,140 KB
testcase_30 AC 439 ms
114,276 KB
testcase_31 AC 431 ms
113,944 KB
testcase_32 AC 425 ms
114,204 KB
testcase_33 AC 406 ms
114,096 KB
testcase_34 AC 465 ms
92,412 KB
testcase_35 AC 405 ms
90,300 KB
testcase_36 AC 405 ms
90,188 KB
testcase_37 AC 364 ms
89,500 KB
testcase_38 AC 448 ms
91,392 KB
testcase_39 AC 259 ms
87,544 KB
testcase_40 AC 260 ms
87,208 KB
testcase_41 AC 257 ms
86,872 KB
testcase_42 AC 254 ms
87,000 KB
testcase_43 AC 263 ms
86,820 KB
testcase_44 AC 293 ms
131,760 KB
testcase_45 AC 289 ms
132,052 KB
testcase_46 AC 254 ms
120,540 KB
testcase_47 AC 247 ms
115,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    Sc=[[] for _ in range(N+1)]
    Sz=[[] for _ in range(N+1)]

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

    inf=float("inf")

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

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

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

    for a in range(N,0,-1):
        for b in Sz[a]:
            if a>b:
                if H[a]<H[b]:
                    DP_z[b][1]=max(DP_z[b][1], DP_z[a][0]+(H[b]-H[a]))
                else:
                    DP_z[b][0]=max(DP_z[b][0], max(DP_z[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