結果
| 問題 |
No.1313 N言っちゃダメゲーム (4)
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2020-12-10 01:15:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 234 ms / 2,000 ms |
| コード長 | 3,413 bytes |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 82,156 KB |
| 実行使用メモリ | 99,072 KB |
| 最終ジャッジ日時 | 2024-09-19 07:39:01 |
| 合計ジャッジ時間 | 5,360 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
class Segment_Tree():
"""
このプログラム内は1-index
"""
def __init__(self,L,calc,unit):
"""calcを演算とするリストLのSegment Treeを作成
calc:演算(2変数関数,モノイド)
unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
"""
self.calc=calc
self.unit=unit
N=len(L)
d=max(1,(N-1).bit_length())
k=1<<d
self.data=[unit]*k+L+[unit]*(k-len(L))
self.N=k
self.depth=d
for i in range(k-1,0,-1):
self.data[i]=calc(self.data[i<<1],self.data[i<<1|1])
def get(self,k,index=1):
"""第k要素を取得
"""
assert 0<=k-index<self.N,"添字が範囲外"
return self.data[k-index+self.N]
def update(self,k,x,index=1):
"""第k要素をxに変え,更新を行う.
k:数列の要素
x:更新後の値
"""
assert 0<=k-index<self.N,"添字が範囲外"
m=(k-index)+self.N
self.data[m]=x
while m>1:
m>>=1
self.data[m]=self.calc(self.data[m<<1],self.data[m<<1|1])
def product(self,From,To,index=1,left_closed=True,right_closed=True):
L=(From-index)+self.N+(not left_closed)
R=(To-index)+self.N+(right_closed)
vL=self.unit
vR=self.unit
while L<R:
if L&1:
vL=self.calc(vL,self.data[L])
L+=1
if R&1:
R-=1
vR=self.calc(self.data[R],vR)
L>>=1
R>>=1
return self.calc(vL,vR)
def all_product(self):
return self.data[1]
def max_right(self,l,r,cond,index=0):
"""以下の2つをともに満たすxの1つを返す.\n
(1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True
(2) r=x or cond(data[l]*data[l+1]*...*data[r]):False
※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.
cond:関数(引数が同じならば結果も同じ)
cond(unit):True
0<=l<=r<=n
"""
l-=index
assert 0<=l<=r<=self.num,"添字が範囲外"
assert cond(self.unit),"単位元が条件を満たさない."
if l==r:
return r+index
l+=(self.num-1)
sm=self.unit
calc=self.calc
while True:
while l%2:
l=(l-1)>>1
if not cond(calc(sm,self.data[l])):
while l<self.num-1:
l=2*l+1
if cond(calc(sm,self.data[l])):
sm=calc(sm,self.data[l])
l+=1
return min(l-(self.num-1)+index,r)
sm=calc(sm,self.data[l])
l+=1
m=l+1
if not (m&(-m) !=m):
break
return r+index
#================================================
N,K=map(int,input().split())
S="*"+input()
if S.count("x")==N:
print(0)
exit(0)
inf=float("inf")
T=Segment_Tree([inf]*(N+1),min,inf)
I=N-1
while S[I]=="x":
I-=1
T.update(I,0,0)
for i in range(N-2,-1,-1):
if S[i]=="x":
continue
p=T.product(i+1,min(N-1,i+K),0)
if p==0:
T.update(i,1,0)
else:
T.update(i,0,0)
if T.get(0,0)==0:
print(0)
else:
for i in range(1,K+1):
if T.get(i,0)==0:
print(i)
Kazun