結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー McGregorshMcGregorsh
提出日時 2022-10-24 23:19:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 2,493 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 81,408 KB
実行使用メモリ 122,240 KB
最終ジャッジ日時 2024-07-03 01:58:39
合計ジャッジ時間 18,854 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
88,832 KB
testcase_01 AC 124 ms
89,088 KB
testcase_02 AC 123 ms
89,216 KB
testcase_03 AC 127 ms
88,960 KB
testcase_04 AC 340 ms
108,032 KB
testcase_05 AC 317 ms
102,408 KB
testcase_06 AC 194 ms
91,520 KB
testcase_07 AC 206 ms
92,544 KB
testcase_08 AC 340 ms
110,464 KB
testcase_09 AC 322 ms
102,144 KB
testcase_10 AC 303 ms
95,488 KB
testcase_11 AC 312 ms
105,216 KB
testcase_12 AC 271 ms
98,900 KB
testcase_13 AC 257 ms
106,112 KB
testcase_14 AC 314 ms
97,284 KB
testcase_15 AC 273 ms
105,728 KB
testcase_16 AC 338 ms
97,536 KB
testcase_17 AC 230 ms
105,228 KB
testcase_18 AC 251 ms
106,624 KB
testcase_19 AC 380 ms
111,360 KB
testcase_20 AC 201 ms
94,792 KB
testcase_21 AC 249 ms
99,516 KB
testcase_22 AC 338 ms
97,536 KB
testcase_23 AC 337 ms
108,032 KB
testcase_24 AC 426 ms
114,560 KB
testcase_25 AC 442 ms
116,352 KB
testcase_26 AC 407 ms
114,560 KB
testcase_27 AC 426 ms
116,992 KB
testcase_28 AC 401 ms
116,224 KB
testcase_29 AC 410 ms
115,840 KB
testcase_30 AC 400 ms
114,560 KB
testcase_31 AC 392 ms
116,096 KB
testcase_32 AC 391 ms
114,688 KB
testcase_33 AC 437 ms
114,688 KB
testcase_34 AC 413 ms
99,840 KB
testcase_35 AC 381 ms
99,840 KB
testcase_36 AC 371 ms
100,352 KB
testcase_37 AC 361 ms
100,736 KB
testcase_38 AC 410 ms
100,352 KB
testcase_39 AC 312 ms
99,104 KB
testcase_40 AC 303 ms
99,140 KB
testcase_41 AC 300 ms
98,688 KB
testcase_42 AC 322 ms
99,200 KB
testcase_43 AC 315 ms
98,944 KB
testcase_44 AC 271 ms
121,856 KB
testcase_45 AC 279 ms
122,240 KB
testcase_46 AC 242 ms
116,224 KB
testcase_47 AC 254 ms
116,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, re
from fractions import Fraction
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement, permutations
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext, ROUND_HALF_UP
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
def get_distance(x1, y1, x2, y2):
	  d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	  return d
def rotate(table):
   	  n_fild = []
   	  for x in zip(*table[::-1]):
   	  	  n_fild.append(x)
   	  return n_fild
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7
MOD2 = 998244353


###関数コピーしたか?###
def main():
   
   N, M = i_map()
   H = i_list()
   nums1 = [[] for i in range(N)]
   nums2 = [[] for i in range(N)]
   for i in range(M):
   	  a, b = i_map()
   	  a -= 1
   	  b -= 1
   	  nums1[a].append(b)
   	  nums2[b].append(a)
   	  
   dp1 = [[-INF] * N for i in range(2)]
   dp1[0][0] = 0
   for i in range(N):
   	  for j in nums1[i]:
   	  	  X = H[i]
   	  	  Y = H[j]
   	  	  if X < Y:
   	  	  	  cost = Y - X
   	  	  	  dp1[1][j] = max(dp1[1][j], dp1[0][i] + cost)
   	  	  else:
   	  	  	  dp1[0][j] = max(dp1[0][j], dp1[0][i], dp1[1][i])
   
   dp2 = [[-INF] * N for i in range(2)]
   dp2[0][-1] = 0
   for i in range(N-1, -1, -1):
   	  for j in nums2[i]:
   	  	  Y = H[i]
   	  	  X = H[j]
   	  	  if X > Y:
   	  	  	  cost = X - Y
   	  	  	  dp2[1][j] = max(dp2[1][j], dp2[0][i] + cost)
   	  	  else:
   	  	  	  dp2[0][j] = max(dp2[0][j], dp2[0][i], dp2[1][i])
   
   if dp1[0][-1] == -INF and dp1[1][-1] == -INF:
   	  print(-1)
   else:
   	  print(max(dp1[0][-1], dp1[1][-1]))
   
   if dp2[0][0] == -INF and dp2[1][0] == -INF:
   	  print(-1)
   else:
   	  print(max(dp2[0][0], dp2[1][0]))
   
   
if __name__ == '__main__':
    main()
0