結果

問題 No.2095 High Rise
ユーザー ygd.ygd.
提出日時 2022-10-07 22:33:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 88,224 KB
最終ジャッジ日時 2023-09-03 13:49:49
合計ジャッジ時間 6,402 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
73,028 KB
testcase_01 AC 110 ms
72,768 KB
testcase_02 AC 111 ms
72,632 KB
testcase_03 AC 113 ms
72,796 KB
testcase_04 AC 112 ms
72,900 KB
testcase_05 AC 111 ms
72,684 KB
testcase_06 AC 113 ms
72,576 KB
testcase_07 AC 113 ms
72,956 KB
testcase_08 AC 111 ms
72,788 KB
testcase_09 AC 111 ms
72,800 KB
testcase_10 AC 110 ms
72,812 KB
testcase_11 AC 112 ms
72,884 KB
testcase_12 AC 136 ms
77,760 KB
testcase_13 AC 119 ms
77,860 KB
testcase_14 AC 126 ms
77,748 KB
testcase_15 AC 122 ms
78,000 KB
testcase_16 AC 121 ms
77,732 KB
testcase_17 AC 150 ms
79,252 KB
testcase_18 AC 146 ms
79,184 KB
testcase_19 AC 128 ms
77,988 KB
testcase_20 AC 149 ms
78,960 KB
testcase_21 AC 166 ms
81,276 KB
testcase_22 AC 279 ms
88,224 KB
testcase_23 AC 280 ms
87,848 KB
testcase_24 AC 284 ms
88,004 KB
testcase_25 AC 280 ms
88,040 KB
testcase_26 AC 281 ms
87,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import math
import bisect
#import itertools
#import random
from heapq import heapify, heappop, heappush
from collections import defaultdict 
#from collections import deque
import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    N,M = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(N)]

    if N == 1:
        print(0)
        exit()

    dp = A[0]
    mn = min(dp)
    loc = set([])
    for i in range(M):
        if dp[i] == mn:
            loc.add(i)

    for i in range(1,N):
        p = [0]*M
        p,dp = dp,p
        for j in range(M):
            if j in loc:
                dp[j] = mn + A[i][j]
            else:
                dp[j] = min(p[j] + A[i][j], mn + A[i-1][j] + A[i][j])
        
        mn = min(dp)
        loc = set([])
        for j in range(M):
            if dp[j] == mn:
                loc.add(j)
        # print(dp)
        
    print(min(dp))


if __name__ == '__main__':
    main()
0