結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-09-10 22:46:08 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 495 ms / 2,000 ms |
| コード長 | 1,064 bytes |
| コンパイル時間 | 171 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 24,792 KB |
| 最終ジャッジ日時 | 2024-06-12 02:13:13 |
| 合計ジャッジ時間 | 7,567 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
import bisect
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)
mod = 998244353
S = input()
N = len(S)
K = int(input())
next = [-1] * N
stack = []
for i, s in enumerate(S):
if s == "(":
stack.append(i)
elif s == ",":
next[stack[-1]] = i
elif s == ")":
stack.pop()
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 += 2
M = next[L]
A = rec(L+1, 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