結果

問題 No.2095 High Rise
ユーザー MasKoaTSMasKoaTS
提出日時 2022-10-07 22:07:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,401 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 227,712 KB
最終ジャッジ日時 2023-09-03 12:47:05
合計ジャッジ時間 14,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
81,384 KB
testcase_01 AC 207 ms
81,464 KB
testcase_02 AC 208 ms
81,424 KB
testcase_03 AC 207 ms
81,256 KB
testcase_04 AC 207 ms
81,404 KB
testcase_05 AC 207 ms
81,144 KB
testcase_06 AC 208 ms
81,144 KB
testcase_07 AC 211 ms
81,252 KB
testcase_08 AC 209 ms
81,412 KB
testcase_09 AC 209 ms
81,320 KB
testcase_10 AC 209 ms
81,440 KB
testcase_11 AC 213 ms
81,248 KB
testcase_12 AC 299 ms
86,264 KB
testcase_13 AC 298 ms
86,696 KB
testcase_14 AC 341 ms
87,356 KB
testcase_15 AC 315 ms
86,932 KB
testcase_16 AC 279 ms
85,828 KB
testcase_17 AC 866 ms
104,332 KB
testcase_18 AC 650 ms
96,492 KB
testcase_19 AC 397 ms
88,484 KB
testcase_20 AC 953 ms
109,152 KB
testcase_21 AC 1,655 ms
131,488 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from functools import cmp_to_key
import math
import sys
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10 ** 6)
inp = sys.stdin.readline
input = lambda : inp().rstrip()
getN = lambda : int(inp())
getNs = lambda : map(int, inp().split())
getList = lambda :list(map(int, inp().split()))
getStrs = lambda n : [input() for _ in [0] * n]
def yexit(): print("Yes"); exit(0)
def nexit(): print("No"); exit(0)
pi = 3.141592653589793
mod = 1000000007
MOD = 998244353
INF = 4611686018427387903
dx = [1, 0, -1, 0];	dy = [0, 1, 0, -1]
#di = coll.defaultdict(int)


"""
Main Code
"""

n, m = getNs()
a = [getList() for _ in [0]*n]

dp = [[[INF]*2 for _ in [0]*m] for _ in [0]*n]
dp[0][0][0] = 0
que = [(0,0,0,0)]
while(que):
	#print(que)
	c,p,q,r = hq.heappop(que)
	if(c > dp[p][q][r]):
		continue
	if(p == n - 1):
		print(c)
		break
	if(q > 0 and c < dp[p][q-1][0]):
		dp[p][q-1][0] = c
		hq.heappush(que, (c,p,q-1,0))
	if(q < m - 1 and c < dp[p][q+1][0]):
		dp[p][q+1][0] = c
		hq.heappush(que, (c,p,q+1,0))
	if(r == 0):
		nc = c + a[p][q]
		if(nc >= dp[p][q][1]):
			continue
		dp[p][q][1] = nc
		hq.heappush(que, (nc,p,q,1))
	else:
		nc = c + a[p+1][q]
		if(nc >= dp[p+1][q][1]):
			continue
		dp[p+1][q][1] = nc
		hq.heappush(que, (nc,p+1,q,1))
0