結果

問題 No.2095 High Rise
ユーザー rlangevinrlangevin
提出日時 2023-01-25 21:30:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,034 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 93,256 KB
最終ジャッジ日時 2023-09-09 06:31:33
合計ジャッジ時間 11,473 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,304 KB
testcase_01 AC 71 ms
71,264 KB
testcase_02 AC 73 ms
71,304 KB
testcase_03 AC 72 ms
71,228 KB
testcase_04 AC 70 ms
71,300 KB
testcase_05 AC 70 ms
71,280 KB
testcase_06 AC 71 ms
71,528 KB
testcase_07 AC 71 ms
71,292 KB
testcase_08 AC 71 ms
71,320 KB
testcase_09 AC 70 ms
71,252 KB
testcase_10 AC 70 ms
71,296 KB
testcase_11 AC 70 ms
71,412 KB
testcase_12 AC 120 ms
78,608 KB
testcase_13 AC 123 ms
78,916 KB
testcase_14 AC 144 ms
79,052 KB
testcase_15 AC 123 ms
78,868 KB
testcase_16 AC 117 ms
78,752 KB
testcase_17 AC 264 ms
80,672 KB
testcase_18 AC 217 ms
79,184 KB
testcase_19 AC 169 ms
78,924 KB
testcase_20 AC 264 ms
79,904 KB
testcase_21 AC 360 ms
81,996 KB
testcase_22 AC 1,029 ms
92,732 KB
testcase_23 AC 981 ms
93,256 KB
testcase_24 AC 987 ms
92,992 KB
testcase_25 AC 1,034 ms
92,640 KB
testcase_26 AC 982 ms
93,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

class SegmentTree:
    def __init__(self, size, f=min, default=10 ** 18):
        self.size = 2**(size-1).bit_length() 
        self.default = default
        self.dat = [default]*(self.size*2) 
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) 
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
    

N, M = map(int, readline().split())
if N == 1:
    print(0)
    exit()
A = []
for i in range(N):
    A.append(list(map(int, readline().split())))
A.append([0]*M)

pre = SegmentTree(M)
for i in range(M):
    pre.update(i, A[0][i] + A[1][i])
    
for i in range(1, N):
    dp = SegmentTree(M)
    for j in range(M):
        now = pre.query(j, j + 1)
        pre.update(j, now - A[i][j])
        dp.update(j, pre.query(0, M) + A[i][j] + A[i + 1][j])
        pre.update(j, now)
    pre, dp = dp, pre
    
print(pre.query(0, M))
0