結果

問題 No.2657 Falling Block Game
ユーザー chineristACchineristAC
提出日時 2024-03-01 22:09:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 615 ms / 2,000 ms
コード長 2,555 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 118,920 KB
最終ジャッジ日時 2024-09-29 14:08:19
合計ジャッジ時間 19,136 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
56,400 KB
testcase_01 AC 45 ms
57,776 KB
testcase_02 AC 43 ms
57,440 KB
testcase_03 AC 46 ms
57,412 KB
testcase_04 AC 174 ms
83,320 KB
testcase_05 AC 449 ms
117,704 KB
testcase_06 AC 353 ms
118,908 KB
testcase_07 AC 495 ms
116,228 KB
testcase_08 AC 478 ms
84,540 KB
testcase_09 AC 386 ms
83,144 KB
testcase_10 AC 378 ms
118,136 KB
testcase_11 AC 363 ms
118,328 KB
testcase_12 AC 361 ms
118,472 KB
testcase_13 AC 383 ms
118,252 KB
testcase_14 AC 362 ms
118,460 KB
testcase_15 AC 365 ms
118,540 KB
testcase_16 AC 364 ms
118,260 KB
testcase_17 AC 351 ms
118,920 KB
testcase_18 AC 360 ms
118,476 KB
testcase_19 AC 350 ms
118,228 KB
testcase_20 AC 558 ms
86,328 KB
testcase_21 AC 561 ms
86,516 KB
testcase_22 AC 570 ms
86,904 KB
testcase_23 AC 589 ms
86,596 KB
testcase_24 AC 571 ms
86,836 KB
testcase_25 AC 615 ms
87,580 KB
testcase_26 AC 581 ms
86,768 KB
testcase_27 AC 568 ms
87,000 KB
testcase_28 AC 563 ms
86,928 KB
testcase_29 AC 568 ms
86,520 KB
testcase_30 AC 560 ms
84,880 KB
testcase_31 AC 535 ms
85,992 KB
testcase_32 AC 564 ms
85,600 KB
testcase_33 AC 568 ms
85,584 KB
testcase_34 AC 543 ms
85,252 KB
testcase_35 AC 533 ms
85,484 KB
testcase_36 AC 545 ms
86,520 KB
testcase_37 AC 550 ms
85,736 KB
testcase_38 AC 537 ms
86,024 KB
testcase_39 AC 538 ms
86,536 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