結果

問題 No.1313 N言っちゃダメゲーム (4)
ユーザー wolgnik
提出日時 2020-12-10 02:05:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 90,368 KB
最終ジャッジ日時 2024-09-19 08:36:41
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 29 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = list(input())[: -1]
dp = [0] * (N + 1)

class FenwickTree:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 2)
  def sum(self, l, r):
    s = 0
    while l > 0:
      s -= self.data[l]
      l -= l & -l
    while r > 0:
      s += self.data[r]
      r -= r & -r
    return s
  def add(self, i, x):
    i += 1
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def lowerbound(self, s):
    x = 0
    y = 0
    for i in range(self.n.bit_length(), -1, -1):
      k = x + (1 << i)
      if k <= self.n and (y + self.data[k] < s):
        y += self.data[k]
        x += 1 << i
    return x + 1

fwk = FenwickTree(N)
fwk.add(N, 1)
dp[-1] = 1
if S[-1] == "x":
  dp[-2] = 1
  fwk.add(N - 1, 1)
for i in range(N - 2, -1, -1):
  if S[i - 1] == "x":
    dp[i] = 1
    fwk.add(i, 1)
    continue
  r = min(N, i + K)
  s = fwk.sum(i, r + 1)
  if s < r - i: dp[i] = 1
  fwk.add(i, dp[i])
for i in range(1, K + 1):
  if dp[i] == 0:
    print(i)
    break
else: print(0)
0