結果
問題 | No.1677 mæx |
ユーザー | taiga0629kyopro |
提出日時 | 2021-09-11 00:00:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 443 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 462 ms |
コンパイル使用メモリ | 87,076 KB |
実行使用メモリ | 139,376 KB |
最終ジャッジ日時 | 2023-09-03 01:33:13 |
合計ジャッジ時間 | 9,908 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,412 KB |
testcase_01 | AC | 71 ms
71,256 KB |
testcase_02 | AC | 74 ms
71,300 KB |
testcase_03 | AC | 72 ms
71,196 KB |
testcase_04 | AC | 397 ms
121,572 KB |
testcase_05 | AC | 405 ms
123,968 KB |
testcase_06 | AC | 396 ms
122,100 KB |
testcase_07 | AC | 408 ms
123,524 KB |
testcase_08 | AC | 408 ms
121,560 KB |
testcase_09 | AC | 402 ms
123,072 KB |
testcase_10 | AC | 392 ms
122,596 KB |
testcase_11 | AC | 403 ms
124,428 KB |
testcase_12 | AC | 407 ms
122,600 KB |
testcase_13 | AC | 391 ms
121,116 KB |
testcase_14 | AC | 419 ms
121,876 KB |
testcase_15 | AC | 425 ms
124,056 KB |
testcase_16 | AC | 420 ms
123,488 KB |
testcase_17 | AC | 422 ms
122,488 KB |
testcase_18 | AC | 417 ms
123,528 KB |
testcase_19 | AC | 72 ms
71,152 KB |
testcase_20 | AC | 69 ms
71,160 KB |
testcase_21 | AC | 443 ms
139,376 KB |
ソースコード
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])