結果
問題 | No.1313 N言っちゃダメゲーム (4) |
ユーザー | brthyyjp |
提出日時 | 2021-04-13 19:42:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 687 ms / 2,000 ms |
コード長 | 2,276 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 87,056 KB |
実行使用メモリ | 121,044 KB |
最終ジャッジ日時 | 2023-09-12 11:58:14 |
合計ジャッジ時間 | 13,133 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
71,856 KB |
testcase_01 | AC | 98 ms
71,616 KB |
testcase_02 | AC | 94 ms
71,856 KB |
testcase_03 | AC | 94 ms
71,708 KB |
testcase_04 | AC | 94 ms
71,604 KB |
testcase_05 | AC | 94 ms
71,860 KB |
testcase_06 | AC | 95 ms
71,736 KB |
testcase_07 | AC | 95 ms
71,676 KB |
testcase_08 | AC | 94 ms
71,772 KB |
testcase_09 | AC | 95 ms
71,640 KB |
testcase_10 | AC | 97 ms
71,780 KB |
testcase_11 | AC | 95 ms
71,620 KB |
testcase_12 | AC | 95 ms
71,648 KB |
testcase_13 | AC | 196 ms
82,524 KB |
testcase_14 | AC | 208 ms
83,636 KB |
testcase_15 | AC | 687 ms
121,044 KB |
testcase_16 | AC | 634 ms
103,580 KB |
testcase_17 | AC | 219 ms
79,872 KB |
testcase_18 | AC | 470 ms
101,444 KB |
testcase_19 | AC | 450 ms
97,028 KB |
testcase_20 | AC | 185 ms
81,184 KB |
testcase_21 | AC | 322 ms
83,760 KB |
testcase_22 | AC | 296 ms
90,584 KB |
testcase_23 | AC | 366 ms
89,072 KB |
testcase_24 | AC | 187 ms
80,040 KB |
testcase_25 | AC | 428 ms
95,112 KB |
testcase_26 | AC | 141 ms
78,048 KB |
testcase_27 | AC | 253 ms
79,920 KB |
testcase_28 | AC | 494 ms
89,168 KB |
testcase_29 | AC | 501 ms
89,064 KB |
testcase_30 | AC | 542 ms
98,540 KB |
testcase_31 | AC | 493 ms
90,848 KB |
testcase_32 | AC | 552 ms
100,076 KB |
testcase_33 | AC | 170 ms
81,476 KB |
testcase_34 | AC | 162 ms
81,456 KB |
testcase_35 | AC | 196 ms
82,476 KB |
testcase_36 | AC | 181 ms
83,392 KB |
testcase_37 | AC | 182 ms
83,792 KB |
ソースコード
class BIT: def __init__(self, n): self.n = n self.bit = [0]*(self.n+1) # 1-indexed def init(self, init_val): for i, v in enumerate(init_val): self.add(i, v) def add(self, i, x): # i: 0-indexed i += 1 # to 1-indexed while i <= self.n: self.bit[i] += x i += (i & -i) def sum(self, i, j): # return sum of [i, j) # i, j: 0-indexed return self._sum(j) - self._sum(i) def _sum(self, i): # return sum of [0, i) # i: 0-indexed res = 0 while i > 0: res += self.bit[i] i -= i & (-i) return res def lower_bound(self, x): s = 0 pos = 0 depth = self.n.bit_length() v = 1 << depth for i in range(depth, -1, -1): k = pos + v if k <= self.n and s + self.bit[k] < x: s += self.bit[k] pos += v v >>= 1 return pos def __str__(self): # for debug arr = [self.sum(i,i+1) for i in range(self.n)] return str(arr) n, k = map(int, input().split()) s = str(input()) s = 'o'+s def mex(bit): ok = -1 ng = k+2 while ok+1 < ng: c = (ng+ok)//2 if bit.sum(0, c+1) < c+1: ng = c else: ok = c #print(ok, ng) return ng from collections import deque, defaultdict bit = BIT(k+2) grundy = [-1]*n if s[n-1] == 'x': grundy[n-1] = k+1 else: grundy[n-1] = 0 q = deque([]) d = defaultdict(lambda:0) for i in range(k): a = grundy[n-1-i] t = bit.sum(a, a+1) bit.add(a, -t) bit.add(a, 1) q.append(a) d[a] += 1 if s[n-1-i-1] !='x': grundy[n-1-i-1] = mex(bit) else: grundy[n-1-i-1] = k+1 #print(grundy) for i in reversed(range(n-k-1)): b = q.popleft() d[b] -= 1 if d[b] == 0: bit.add(b, -1) a = grundy[i+1] if d[a] == 0: bit.add(a, 1) d[a] += 1 q.append(a) if s[i] != 'x': grundy[i] = mex(bit) else: grundy[i] = k+1 #print(grundy) if grundy[0] == 0: print(0) exit() ans = [] for i in range(1, k+1): if grundy[i] == 0: ans.append(i) print(*ans, sep='\n')