結果

問題 No.2657 Falling Block Game
ユーザー PNJPNJ
提出日時 2024-03-01 22:27:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 780 ms / 2,000 ms
コード長 3,491 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 174,312 KB
最終ジャッジ日時 2024-03-01 22:27:55
合計ジャッジ時間 21,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 238 ms
88,804 KB
testcase_05 AC 470 ms
147,300 KB
testcase_06 AC 381 ms
124,376 KB
testcase_07 AC 289 ms
174,312 KB
testcase_08 AC 157 ms
81,676 KB
testcase_09 AC 301 ms
92,388 KB
testcase_10 AC 367 ms
135,268 KB
testcase_11 AC 372 ms
135,524 KB
testcase_12 AC 363 ms
135,524 KB
testcase_13 AC 362 ms
135,524 KB
testcase_14 AC 372 ms
137,060 KB
testcase_15 AC 362 ms
135,140 KB
testcase_16 AC 363 ms
135,396 KB
testcase_17 AC 378 ms
135,392 KB
testcase_18 AC 368 ms
135,396 KB
testcase_19 AC 366 ms
135,524 KB
testcase_20 AC 762 ms
91,028 KB
testcase_21 AC 733 ms
91,048 KB
testcase_22 AC 770 ms
91,444 KB
testcase_23 AC 693 ms
89,164 KB
testcase_24 AC 680 ms
89,612 KB
testcase_25 AC 780 ms
90,680 KB
testcase_26 AC 752 ms
90,428 KB
testcase_27 AC 773 ms
90,748 KB
testcase_28 AC 704 ms
89,340 KB
testcase_29 AC 763 ms
91,576 KB
testcase_30 AC 622 ms
94,780 KB
testcase_31 AC 579 ms
94,216 KB
testcase_32 AC 567 ms
93,664 KB
testcase_33 AC 556 ms
93,552 KB
testcase_34 AC 565 ms
93,512 KB
testcase_35 AC 548 ms
94,028 KB
testcase_36 AC 619 ms
95,000 KB
testcase_37 AC 687 ms
96,732 KB
testcase_38 AC 575 ms
93,660 KB
testcase_39 AC 664 ms
95,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segtree():
    n=1
    size=1
    log=2
    d=[0]
    op=None
    e=10**15
    def __init__(self,V,OP,E):
        self.n=len(V)
        self.op=OP
        self.e=E
        self.log=(self.n-1).bit_length()
        self.size=1<<self.log
        self.d=[E for i in range(2*self.size)]
        for i in range(self.n):
            self.d[self.size+i]=V[i]
        for i in range(self.size-1,0,-1):
            self.update(i)
    def set(self,p,x):
        assert 0<=p and p<self.n
        p+=self.size
        self.d[p]=x
        for i in range(1,self.log+1):
            self.update(p>>i)
    def get(self,p):
        assert 0<=p and p<self.n
        return self.d[p+self.size]
    def prod(self,l,r):
        assert 0<=l and l<=r and r<=self.n
        sml=self.e
        smr=self.e
        l+=self.size
        r+=self.size
        while(l<r):
            if (l&1):
                sml=self.op(sml,self.d[l])
                l+=1
            if (r&1):
                smr=self.op(self.d[r-1],smr)
                r-=1
            l>>=1
            r>>=1
        return self.op(sml,smr)
    def all_prod(self):
        return self.d[1]
    def max_right(self,l,f):
        assert 0<=l and l<=self.n
        assert f(self.e)
        if l==self.n:
            return self.n
        l+=self.size
        sm=self.e
        while(1):
            while(l%2==0):
                l>>=1
            if not(f(self.op(sm,self.d[l]))):
                while(l<self.size):
                    l=2*l
                    if f(self.op(sm,self.d[l])):
                        sm=self.op(sm,self.d[l])
                        l+=1
                return l-self.size
            sm=self.op(sm,self.d[l])
            l+=1
            if (l&-l)==l:
                break
        return self.n
    def min_left(self,r,f):
        assert 0<=r and r<=self.n
        assert f(self.e)
        if r==0:
            return 0
        r+=self.size
        sm=self.e
        while(1):
            r-=1
            while(r>1 and (r%2)):
                r>>=1
            if not(f(self.op(self.d[r],sm))):
                while(r<self.size):
                    r=(2*r+1)
                    if f(self.op(self.d[r],sm)):
                        sm=self.op(self.d[r],sm)
                        r-=1
                return r+1-self.size
            sm=self.op(self.d[r],sm)
            if (r& -r)==r:
                break
        return 0
    def update(self,k):
        self.d[k]=self.op(self.d[2*k],self.d[2*k+1])
    def __str__(self):
        return str([self.get(i) for i in range(self.n)])

H,W = map(int,input().split())
S = [input() for i in range(H)]
inf = 10**18
dp = [[inf for w in range(W)] for h in range(H)]
T = []
for w in range(W):
  T.append((H-1,w))
  dp[H-1][w] = 0

for h in range(H-2,-1,-1):
  X = [[] for w in range(W)]
  Y = [[] for w in range(W)]
  seg = segtree(dp[h+1],min,inf)
  for w in range(W):
    c = dp[h+1][w]
    if w + c < W:
      X[w+c].append(w)
    if w - c > 0:
      Y[w-c].append(w)

  i = -1
  b = -1
  for w in range(W):
    for j in X[w]:
      i = max(i,j)
    if S[h][w] == '#':
      b = w
      continue
    res = seg.prod(max(i,b)+1,w+1)
    if i > b:
      res = min(res,w-i)
    dp[h][w] = res
  i = W
  b = W
  for w in range(W-1,-1,-1):
    for j in Y[w]:
      i = min(i,j)
    if S[h][w] == '#':
      b = w
      continue
    res = seg.prod(w,min(i,b))
    if i < b:
      res = min(res,i - w)
    dp[h][w] = min(dp[h][w],res)

for k in range(W):
  print(dp[0][k])
0