結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー ntudantuda
提出日時 2022-10-19 22:43:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 540 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 130,516 KB
最終ジャッジ日時 2023-09-12 10:12:51
合計ジャッジ時間 18,186 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,404 KB
testcase_01 AC 73 ms
71,396 KB
testcase_02 AC 73 ms
71,368 KB
testcase_03 AC 72 ms
71,132 KB
testcase_04 AC 402 ms
116,440 KB
testcase_05 AC 315 ms
100,844 KB
testcase_06 AC 167 ms
83,104 KB
testcase_07 AC 184 ms
86,952 KB
testcase_08 AC 372 ms
121,172 KB
testcase_09 AC 325 ms
105,464 KB
testcase_10 AC 248 ms
90,616 KB
testcase_11 AC 345 ms
109,336 KB
testcase_12 AC 269 ms
94,184 KB
testcase_13 AC 265 ms
102,344 KB
testcase_14 AC 261 ms
93,604 KB
testcase_15 AC 302 ms
108,896 KB
testcase_16 AC 279 ms
92,316 KB
testcase_17 AC 226 ms
102,528 KB
testcase_18 AC 298 ms
109,420 KB
testcase_19 AC 431 ms
123,796 KB
testcase_20 AC 201 ms
86,396 KB
testcase_21 AC 269 ms
96,892 KB
testcase_22 AC 263 ms
93,848 KB
testcase_23 AC 402 ms
116,044 KB
testcase_24 AC 532 ms
130,036 KB
testcase_25 AC 540 ms
130,516 KB
testcase_26 AC 438 ms
122,488 KB
testcase_27 AC 444 ms
122,364 KB
testcase_28 AC 439 ms
122,540 KB
testcase_29 AC 445 ms
122,536 KB
testcase_30 AC 445 ms
121,868 KB
testcase_31 AC 453 ms
122,268 KB
testcase_32 AC 444 ms
122,164 KB
testcase_33 AC 500 ms
129,892 KB
testcase_34 AC 313 ms
100,172 KB
testcase_35 AC 294 ms
98,308 KB
testcase_36 AC 297 ms
98,304 KB
testcase_37 AC 291 ms
97,952 KB
testcase_38 AC 299 ms
99,136 KB
testcase_39 AC 266 ms
97,556 KB
testcase_40 AC 266 ms
97,424 KB
testcase_41 AC 263 ms
97,136 KB
testcase_42 AC 265 ms
97,520 KB
testcase_43 AC 270 ms
96,928 KB
testcase_44 AC 271 ms
122,572 KB
testcase_45 AC 269 ms
122,704 KB
testcase_46 AC 268 ms
124,848 KB
testcase_47 AC 265 ms
124,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
H = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(M)]
# dp[i][j]:= 足場iにいてその前の移動が昇り:1,下り:0のときの登った回数の最大値
E = [[] for _ in range(N)]
for x, y in XY:
    E[x - 1].append(y - 1)
dp = [[-10 ** 12, -10 ** 12] for _ in range(N)]
dp[0][0] = 0
dp[0][1] = 0
for x in range(N):
    hx = H[x]
    for y in E[x]:
        hy = H[y]
        if hy > hx:
            dp[y][1] = max(dp[y][1], dp[x][0] + hy - hx)
        else:
            dp[y][0] = max(dp[y][0], dp[x][1], dp[x][0])
ans = []
ans.append(max(dp[N - 1]))
E = [[] for _ in range(N)]
for x, y in XY:
    E[y - 1].append(x - 1)
dp = [[-10 ** 12, -10 ** 12] for _ in range(N)]
dp[N - 1][0] = 0
dp[N - 1][1] = 0
for y in reversed(range(N)):
    hy = H[y]
    for x in E[y]:
        hx = H[x]
        if hx > hy:
            dp[x][1] = max(dp[x][1], dp[y][0] + hx - hy)
        else:
            dp[x][0] = max(dp[x][0], dp[y][1], dp[y][0])
ans.append(max(dp[0]))
for i in range(2):
    if ans[i] < 0:
        print(-1)
    else:
        print(ans[i])
0