結果

問題 No.2657 Falling Block Game
ユーザー chineristACchineristAC
提出日時 2024-03-01 22:09:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 811 ms / 2,000 ms
コード長 2,555 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 118,488 KB
最終ジャッジ日時 2024-03-01 22:09:33
合計ジャッジ時間 25,121 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
58,344 KB
testcase_01 AC 45 ms
58,344 KB
testcase_02 AC 45 ms
58,344 KB
testcase_03 AC 45 ms
58,344 KB
testcase_04 AC 231 ms
82,644 KB
testcase_05 AC 526 ms
117,148 KB
testcase_06 AC 417 ms
118,488 KB
testcase_07 AC 616 ms
115,724 KB
testcase_08 AC 597 ms
84,004 KB
testcase_09 AC 574 ms
82,472 KB
testcase_10 AC 436 ms
117,724 KB
testcase_11 AC 407 ms
117,716 KB
testcase_12 AC 410 ms
118,000 KB
testcase_13 AC 411 ms
117,592 KB
testcase_14 AC 434 ms
117,804 KB
testcase_15 AC 405 ms
117,644 KB
testcase_16 AC 412 ms
117,844 KB
testcase_17 AC 409 ms
117,976 KB
testcase_18 AC 428 ms
117,852 KB
testcase_19 AC 410 ms
117,688 KB
testcase_20 AC 707 ms
85,928 KB
testcase_21 AC 740 ms
86,272 KB
testcase_22 AC 705 ms
85,984 KB
testcase_23 AC 720 ms
86,076 KB
testcase_24 AC 731 ms
85,680 KB
testcase_25 AC 737 ms
86,788 KB
testcase_26 AC 736 ms
85,576 KB
testcase_27 AC 684 ms
86,396 KB
testcase_28 AC 745 ms
86,568 KB
testcase_29 AC 703 ms
85,956 KB
testcase_30 AC 774 ms
85,632 KB
testcase_31 AC 798 ms
84,936 KB
testcase_32 AC 763 ms
85,488 KB
testcase_33 AC 769 ms
85,560 KB
testcase_34 AC 777 ms
85,356 KB
testcase_35 AC 732 ms
84,436 KB
testcase_36 AC 811 ms
85,876 KB
testcase_37 AC 803 ms
85,464 KB
testcase_38 AC 752 ms
85,896 KB
testcase_39 AC 757 ms
86,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class deletable_pq:
    def __init__(self):
        self.pq = []
        self.delete_pq = []
    
    def pop(self):
        while self.pq and self.delete_pq and self.pq[0] == self.delete_pq[0]:
            heappop(self.pq)
            heappop(self.delete_pq)
        if not self.pq:
            assert False
        return -heappop(self.pq)
    
    def top(self):
        while self.pq and self.delete_pq and self.pq[0] == self.delete_pq[0]:
            heappop(self.pq)
            heappop(self.delete_pq)
        if not self.pq:
            return -1
        return -self.pq[0]
    
    def add(self,val):
        heappush(self.pq,-val)
    
    def remove(self,val):
        heappush(self.delete_pq,-val)

    def debug(self):
        print(self.pq,self.delete_pq)

class DualSegmentTree:
    def __init__(self, n):
        self.num = 1 << (n - 1).bit_length()
        self.tree = [2*10**9 for i in range(2*self.num)]

    def update(self,l,r,x):
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                self.tree[l] = min(self.tree[l],x)
                l += 1
            if r & 1:
                self.tree[r-1] = min(self.tree[r-1],x)
            l >>= 1
            r >>= 1

    def __getitem__(self,idx):
        idx += self.num
        res = 2*10**9
        while idx:
            res = min(res,self.tree[idx])
            idx>>=1
        return res

H,W = mi()
S = [input() for i in range(H)]

INF = 10**9

dp = [0] * W
for i in range(H-1)[::-1]:
    dec_min = DualSegmentTree(W)
    inc_min = DualSegmentTree(W)
    const_min = DualSegmentTree(W)

    left = [j for j in range(W)]
    for j in range(1,W):
        if S[i][j-1] == "." and S[i][j] == ".":
            left[j] = left[j-1]
    right = [j for j in range(W)]
    for j in range(W-1)[::-1]:
        if S[i][j+1] == "." and S[i][j] == ".":
            right[j] = right[j+1]

    for j in range(W):
        if S[i+1][j] == "#" or S[i][j] == "#":
            continue
        k = dp[j]
        L,R = max(left[j],j-k),min(right[j],j+k)
        #print(L,R,k)
        const_min.update(L,R+1,k)

        dec_min.update(left[j],L,j)
        inc_min.update(R+1,right[j]+1,-j)
    
    dp = [min(dec_min[j]-j,j+inc_min[j],const_min[j],INF) for j in range(W)]
    #print(i,dp)

print(*dp,sep="\n")
0