結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-09-10 22:40:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,158 bytes |
| コンパイル時間 | 208 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 20,052 KB |
| 最終ジャッジ日時 | 2024-06-12 01:54:24 |
| 合計ジャッジ時間 | 3,775 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 RE * 16 |
ソースコード
from collections import defaultdict
import bisect
mod = 998244353
S = input()
N = len(S)
K = int(input())
sep = defaultdict(list)
brac = [0] * N
for i in range(1, N):
if S[i] == "(":
brac[i] = brac[i-1] + 1
elif S[i] == ")":
brac[i] = brac[i-1] - 1
else:
brac[i] = brac[i-1]
if S[i] == ",":
sep[brac[i]].append(i)
def mex(a, b):
for i in range(3):
if not i in [a, b]:
return i
def rec(L, R):
if L + 1 >= R:
if S[L] == "?":
return [1, 1, 1]
res = [0, 0, 0]
res[int(S[L])] += 1
return res
R -= 1
L += 1
oper = []
if S[L] == "?" or S[L] == "a":
oper.append(max)
if S[L] == "?" or S[L] == "e":
oper.append(mex)
L += 3
dep = brac[L]
p = bisect.bisect_left(sep[dep], L)
M = sep[dep][p]
A = rec(L, M)
B = rec(M+1, R)
res = [0, 0, 0]
for op in oper:
for i, a in enumerate(A):
for j, b in enumerate(B):
idx = op(i, j)
res[idx] += a * b % mod
res[idx] %= mod
return res
ans = rec(0, N)[K]
print(ans)
tktk_snsn