結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
taiga0629kyopro
|
| 提出日時 | 2021-09-11 00:00:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 443 ms / 2,000 ms |
| コード長 | 1,078 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 135,460 KB |
| 最終ジャッジ日時 | 2024-06-12 07:04:54 |
| 合計ジャッジ時間 | 7,987 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
s=list(input())
n=len(s)
p=int(input())
stack=[]
ktok={}
mod=998244353
def mex(x,y):
res=set()
res.add(x)
res.add(y)
for i in range(3):
if i not in res:return i
for i in range(n):
if s[i]=="(":stack.append(i)
if s[i]==")":
j=stack.pop()
ktok[j]=i
ktot={}
for i in range(n):
if s[i]=="(":stack.append(i)
if s[i]==",":
j=stack.pop()
ktot[j]=i
def f(l,r):
if l==r:
res=[0,0,0]
if s[l]=="?":
res[0]=1
res[1]=1
res[2]=1
else:
res[int(s[l])]=1
return res
dp1=f(l+4,ktot[l+3]-1)
dp2=f(ktot[l+3]+1,r-1)
res=[0,0,0]
for i in range(3):
for j in range(3):
if s[l+1]=="a" or s[l+1]=="?":
res[max(i,j)]+=dp1[i]*dp2[j]%mod
res[max(i, j)]%=mod
if s[l + 1] == "e" or s[l + 1] == "?":
res[mex(i, j)] += dp1[i] * dp2[j] % mod
res[mex(i, j)] %= mod
return res
print(f(0,n-1)[p])
taiga0629kyopro