結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー flygonflygon
提出日時 2022-10-14 22:44:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 109,312 KB
最終ジャッジ日時 2023-09-08 23:05:23
合計ジャッジ時間 19,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,492 KB
testcase_01 AC 68 ms
71,196 KB
testcase_02 AC 67 ms
71,200 KB
testcase_03 AC 66 ms
71,072 KB
testcase_04 AC 339 ms
94,644 KB
testcase_05 AC 288 ms
93,432 KB
testcase_06 AC 158 ms
82,072 KB
testcase_07 AC 170 ms
85,020 KB
testcase_08 AC 335 ms
105,836 KB
testcase_09 AC 269 ms
92,384 KB
testcase_10 AC 211 ms
82,528 KB
testcase_11 AC 288 ms
96,616 KB
testcase_12 AC 233 ms
89,460 KB
testcase_13 AC 251 ms
99,568 KB
testcase_14 AC 220 ms
85,276 KB
testcase_15 AC 272 ms
98,220 KB
testcase_16 AC 229 ms
85,372 KB
testcase_17 AC 199 ms
91,096 KB
testcase_18 AC 270 ms
99,908 KB
testcase_19 AC 368 ms
105,044 KB
testcase_20 AC 183 ms
84,584 KB
testcase_21 AC 237 ms
90,392 KB
testcase_22 AC 220 ms
85,204 KB
testcase_23 AC 350 ms
101,748 KB
testcase_24 AC 434 ms
109,304 KB
testcase_25 AC 431 ms
109,236 KB
testcase_26 AC 409 ms
108,896 KB
testcase_27 AC 396 ms
108,952 KB
testcase_28 AC 397 ms
109,016 KB
testcase_29 AC 393 ms
109,312 KB
testcase_30 AC 387 ms
109,164 KB
testcase_31 AC 399 ms
109,192 KB
testcase_32 AC 401 ms
109,164 KB
testcase_33 AC 415 ms
109,072 KB
testcase_34 AC 272 ms
87,476 KB
testcase_35 AC 250 ms
86,740 KB
testcase_36 AC 250 ms
87,572 KB
testcase_37 AC 244 ms
86,812 KB
testcase_38 AC 258 ms
87,452 KB
testcase_39 AC 218 ms
86,492 KB
testcase_40 AC 217 ms
86,384 KB
testcase_41 AC 215 ms
86,580 KB
testcase_42 AC 217 ms
86,668 KB
testcase_43 AC 246 ms
86,344 KB
testcase_44 AC 210 ms
100,536 KB
testcase_45 AC 211 ms
100,312 KB
testcase_46 AC 202 ms
101,804 KB
testcase_47 AC 206 ms
101,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
h = list(map(int,input().split()))
graph = [[] for i in range(n+1)]
for i in range(m):
  a,b = map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

for i in range(n):
  graph[i].sort()

INF = 10**18
dp = [[-INF,-INF] for i in range(n)]
dp[0] = [0,0]
for crr in range(n):
  hc = h[crr]
  for nxt in graph[crr][::-1]:
    if crr > nxt: break
    hn = h[nxt]
    if hn > hc:
      dp[nxt][1] = max(dp[nxt][1], dp[crr][0] + hn - hc)
    else:
      dp[nxt][0] = max(dp[nxt][0], dp[crr][1], dp[crr][0])
ans = max(dp[-1])
print(-1) if ans < 0 else print(ans)

dp = [[-INF,-INF] for i in range(n)]
dp[n-1] = [0,0]
for crr in range(n)[::-1]:
  hc = h[crr]
  for nxt in graph[crr]:
    if crr < nxt: break
    hn = h[nxt]
    if hn > hc:
      dp[nxt][1] = max(dp[nxt][1], dp[crr][0] + hn - hc)
    else:
      dp[nxt][0] = max(dp[nxt][0], dp[crr][1], dp[crr][0])

ans = max(dp[0])
print(-1) if ans < 0 else print(ans)
0