結果

問題 No.2095 High Rise
ユーザー terasaterasa
提出日時 2022-10-07 22:23:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 95,832 KB
最終ジャッジ日時 2023-09-03 13:24:13
合計ジャッジ時間 5,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
72,624 KB
testcase_01 AC 108 ms
72,656 KB
testcase_02 AC 108 ms
72,708 KB
testcase_03 AC 105 ms
72,660 KB
testcase_04 AC 106 ms
72,744 KB
testcase_05 AC 106 ms
72,608 KB
testcase_06 AC 107 ms
72,512 KB
testcase_07 AC 110 ms
72,552 KB
testcase_08 AC 109 ms
72,880 KB
testcase_09 AC 107 ms
72,604 KB
testcase_10 AC 105 ms
72,860 KB
testcase_11 AC 105 ms
72,916 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
# import pypyjit
import itertools
import heapq
import math
import bisect
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key


# for AtCoder Easy test
if __file__ == 'prog.py':
    pass
else:
    sys.setrecursionlimit(10 ** 6)
# pypyjit.set_param('max_unroll_recursion=-1')

input = sys.stdin.readline


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]


N, M = readints()
A = [readlist() for _ in range(N)]
if N == 1:
    print(0)
    exit()

INF = 1 << 50
B = [(INF, -1)]
for i in range(N - 1):
    acc = INF
    idx = None
    for j in range(M):
        if A[i][j] + A[i + 1][j] < acc:
            acc = A[i][j] + A[i + 1][j]
            idx = j
    B.append((acc, idx))

dp = [[INF for _ in range(M)] for _ in range(N + 1)]
dp[0] = [0] * M
for i in range(N):
    mc, mi = B[i]
    for j in range(M):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + A[i][j])
        dp[i + 1][mi] = min(dp[i + 1][mi], dp[i][j] + mc)
print(min(dp[N]))
0