結果

問題 No.2095 High Rise
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-10 10:34:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 990 ms / 2,000 ms
コード長 2,099 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 102,088 KB
最終ジャッジ日時 2023-09-06 11:28:57
合計ジャッジ時間 11,875 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,832 KB
testcase_01 AC 103 ms
72,912 KB
testcase_02 AC 104 ms
72,740 KB
testcase_03 AC 104 ms
72,552 KB
testcase_04 AC 103 ms
72,912 KB
testcase_05 AC 102 ms
72,684 KB
testcase_06 AC 102 ms
72,716 KB
testcase_07 AC 104 ms
72,476 KB
testcase_08 AC 104 ms
72,612 KB
testcase_09 AC 105 ms
72,688 KB
testcase_10 AC 104 ms
72,764 KB
testcase_11 AC 105 ms
72,552 KB
testcase_12 AC 162 ms
81,080 KB
testcase_13 AC 166 ms
81,004 KB
testcase_14 AC 171 ms
80,804 KB
testcase_15 AC 168 ms
80,848 KB
testcase_16 AC 158 ms
80,720 KB
testcase_17 AC 327 ms
84,100 KB
testcase_18 AC 247 ms
82,400 KB
testcase_19 AC 192 ms
81,196 KB
testcase_20 AC 342 ms
85,356 KB
testcase_21 AC 442 ms
86,784 KB
testcase_22 AC 990 ms
101,880 KB
testcase_23 AC 977 ms
101,900 KB
testcase_24 AC 980 ms
101,296 KB
testcase_25 AC 975 ms
101,908 KB
testcase_26 AC 970 ms
102,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from itertools import *
from functools import *
import math,sys
input = sys.stdin.readline

N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
if N==1:
    print(0)
    exit()
INF = (1<<60)
dp = [[INF]*M for _ in range(N)]
for i in range(M):
    dp[0][i] = A[0][i]

def segfunc(x, y):
    return min(x,y)

ide_ele = float('inf')


class SegTree:
    """
    Segment Tree
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        初期化

        init_val: 配列の初期値
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新

        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る

        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

for i in range(N-1):
    
    T = SegTree(dp[i],segfunc,ide_ele)
    
    for j in range(M):
        
        dp[i+1][j] = min(dp[i][j] + A[i+1][j],min(T.query(0,j),T.query(j+1,M)) + A[i+1][j]+A[i][j] )
        
print(min(dp[-1]))
0