結果

問題 No.1313 N言っちゃダメゲーム (4)
ユーザー 👑 KazunKazun
提出日時 2020-12-10 01:15:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 3,413 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 81,696 KB
実行使用メモリ 98,204 KB
最終ジャッジ日時 2023-10-19 11:32:20
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,528 KB
testcase_01 AC 40 ms
53,528 KB
testcase_02 AC 40 ms
53,528 KB
testcase_03 AC 39 ms
53,528 KB
testcase_04 AC 40 ms
53,528 KB
testcase_05 AC 40 ms
53,528 KB
testcase_06 AC 39 ms
53,528 KB
testcase_07 AC 40 ms
53,528 KB
testcase_08 AC 40 ms
53,528 KB
testcase_09 AC 40 ms
53,528 KB
testcase_10 AC 40 ms
53,528 KB
testcase_11 AC 39 ms
53,528 KB
testcase_12 AC 39 ms
53,528 KB
testcase_13 AC 63 ms
84,116 KB
testcase_14 AC 67 ms
84,488 KB
testcase_15 AC 225 ms
98,172 KB
testcase_16 AC 256 ms
98,204 KB
testcase_17 AC 180 ms
97,676 KB
testcase_18 AC 205 ms
87,236 KB
testcase_19 AC 193 ms
87,008 KB
testcase_20 AC 128 ms
79,528 KB
testcase_21 AC 184 ms
86,620 KB
testcase_22 AC 149 ms
81,400 KB
testcase_23 AC 190 ms
87,064 KB
testcase_24 AC 127 ms
78,120 KB
testcase_25 AC 203 ms
87,476 KB
testcase_26 AC 100 ms
75,960 KB
testcase_27 AC 178 ms
86,496 KB
testcase_28 AC 252 ms
98,144 KB
testcase_29 AC 235 ms
98,144 KB
testcase_30 AC 242 ms
98,204 KB
testcase_31 AC 246 ms
98,204 KB
testcase_32 AC 253 ms
98,144 KB
testcase_33 AC 68 ms
86,576 KB
testcase_34 AC 68 ms
86,568 KB
testcase_35 AC 62 ms
84,136 KB
testcase_36 AC 63 ms
84,272 KB
testcase_37 AC 67 ms
84,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0