結果

問題 No.2095 High Rise
ユーザー terasaterasa
提出日時 2022-10-07 22:24:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 108,760 KB
最終ジャッジ日時 2023-09-03 13:29:26
合計ジャッジ時間 7,211 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
72,672 KB
testcase_01 AC 103 ms
72,676 KB
testcase_02 AC 103 ms
72,852 KB
testcase_03 AC 102 ms
72,816 KB
testcase_04 AC 101 ms
72,576 KB
testcase_05 AC 105 ms
72,676 KB
testcase_06 AC 104 ms
72,788 KB
testcase_07 AC 106 ms
72,800 KB
testcase_08 AC 103 ms
72,672 KB
testcase_09 AC 100 ms
72,512 KB
testcase_10 AC 97 ms
72,580 KB
testcase_11 AC 96 ms
72,744 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 = float('inf')
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