結果
問題 | No.1313 N言っちゃダメゲーム (4) |
ユーザー | brthyyjp |
提出日時 | 2021-04-13 19:42:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 532 ms / 2,000 ms |
コード長 | 2,276 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 119,496 KB |
最終ジャッジ日時 | 2024-06-30 00:25:54 |
合計ジャッジ時間 | 8,511 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,144 KB |
testcase_01 | AC | 41 ms
54,144 KB |
testcase_02 | AC | 44 ms
54,016 KB |
testcase_03 | AC | 48 ms
53,760 KB |
testcase_04 | AC | 45 ms
53,760 KB |
testcase_05 | AC | 45 ms
53,632 KB |
testcase_06 | AC | 44 ms
54,016 KB |
testcase_07 | AC | 44 ms
54,016 KB |
testcase_08 | AC | 45 ms
53,888 KB |
testcase_09 | AC | 41 ms
54,016 KB |
testcase_10 | AC | 39 ms
54,016 KB |
testcase_11 | AC | 39 ms
54,144 KB |
testcase_12 | AC | 39 ms
54,016 KB |
testcase_13 | AC | 129 ms
80,896 KB |
testcase_14 | AC | 147 ms
82,432 KB |
testcase_15 | AC | 532 ms
119,496 KB |
testcase_16 | AC | 508 ms
103,284 KB |
testcase_17 | AC | 171 ms
79,104 KB |
testcase_18 | AC | 382 ms
99,204 KB |
testcase_19 | AC | 357 ms
94,832 KB |
testcase_20 | AC | 141 ms
79,744 KB |
testcase_21 | AC | 262 ms
81,664 KB |
testcase_22 | AC | 232 ms
88,576 KB |
testcase_23 | AC | 268 ms
86,736 KB |
testcase_24 | AC | 140 ms
78,208 KB |
testcase_25 | AC | 330 ms
93,888 KB |
testcase_26 | AC | 93 ms
77,440 KB |
testcase_27 | AC | 184 ms
79,144 KB |
testcase_28 | AC | 356 ms
87,424 KB |
testcase_29 | AC | 381 ms
87,632 KB |
testcase_30 | AC | 403 ms
95,732 KB |
testcase_31 | AC | 358 ms
88,068 KB |
testcase_32 | AC | 414 ms
97,156 KB |
testcase_33 | AC | 117 ms
80,768 KB |
testcase_34 | AC | 107 ms
79,488 KB |
testcase_35 | AC | 134 ms
81,792 KB |
testcase_36 | AC | 125 ms
81,920 KB |
testcase_37 | AC | 126 ms
82,688 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')