結果
問題 | No.2657 Falling Block Game |
ユーザー | PNJ |
提出日時 | 2024-03-01 22:27:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 739 ms / 2,000 ms |
コード長 | 3,491 bytes |
コンパイル時間 | 269 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 174,896 KB |
最終ジャッジ日時 | 2024-09-29 14:31:53 |
合計ジャッジ時間 | 19,977 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
54,456 KB |
testcase_01 | AC | 38 ms
53,900 KB |
testcase_02 | AC | 40 ms
53,244 KB |
testcase_03 | AC | 38 ms
53,020 KB |
testcase_04 | AC | 213 ms
89,508 KB |
testcase_05 | AC | 444 ms
147,312 KB |
testcase_06 | AC | 367 ms
124,660 KB |
testcase_07 | AC | 270 ms
174,896 KB |
testcase_08 | AC | 152 ms
82,608 KB |
testcase_09 | AC | 273 ms
92,956 KB |
testcase_10 | AC | 356 ms
135,308 KB |
testcase_11 | AC | 359 ms
135,676 KB |
testcase_12 | AC | 355 ms
136,068 KB |
testcase_13 | AC | 348 ms
135,688 KB |
testcase_14 | AC | 355 ms
135,388 KB |
testcase_15 | AC | 357 ms
135,944 KB |
testcase_16 | AC | 359 ms
136,020 KB |
testcase_17 | AC | 361 ms
135,536 KB |
testcase_18 | AC | 358 ms
135,432 KB |
testcase_19 | AC | 359 ms
135,532 KB |
testcase_20 | AC | 729 ms
90,924 KB |
testcase_21 | AC | 715 ms
91,104 KB |
testcase_22 | AC | 732 ms
92,268 KB |
testcase_23 | AC | 686 ms
90,160 KB |
testcase_24 | AC | 664 ms
89,344 KB |
testcase_25 | AC | 730 ms
91,704 KB |
testcase_26 | AC | 726 ms
91,984 KB |
testcase_27 | AC | 725 ms
91,536 KB |
testcase_28 | AC | 658 ms
89,684 KB |
testcase_29 | AC | 739 ms
91,988 KB |
testcase_30 | AC | 551 ms
94,424 KB |
testcase_31 | AC | 548 ms
94,464 KB |
testcase_32 | AC | 519 ms
94,072 KB |
testcase_33 | AC | 531 ms
94,196 KB |
testcase_34 | AC | 516 ms
94,284 KB |
testcase_35 | AC | 535 ms
94,268 KB |
testcase_36 | AC | 584 ms
95,056 KB |
testcase_37 | AC | 684 ms
98,504 KB |
testcase_38 | AC | 553 ms
94,336 KB |
testcase_39 | AC | 656 ms
96,344 KB |
ソースコード
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])