結果

問題 No.1677 mæx
ユーザー とりゐとりゐ
提出日時 2023-06-06 15:00:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 127,568 KB
最終ジャッジ日時 2023-08-28 10:42:32
合計ジャッジ時間 6,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,244 KB
testcase_01 AC 71 ms
71,284 KB
testcase_02 AC 69 ms
71,116 KB
testcase_03 AC 71 ms
71,292 KB
testcase_04 AC 254 ms
110,288 KB
testcase_05 AC 268 ms
112,416 KB
testcase_06 AC 258 ms
109,404 KB
testcase_07 AC 256 ms
110,624 KB
testcase_08 AC 255 ms
110,904 KB
testcase_09 AC 260 ms
110,740 KB
testcase_10 AC 258 ms
109,736 KB
testcase_11 AC 257 ms
112,200 KB
testcase_12 AC 259 ms
110,036 KB
testcase_13 AC 258 ms
110,904 KB
testcase_14 AC 247 ms
110,360 KB
testcase_15 AC 255 ms
114,256 KB
testcase_16 AC 245 ms
109,096 KB
testcase_17 AC 245 ms
109,640 KB
testcase_18 AC 253 ms
109,316 KB
testcase_19 AC 72 ms
71,500 KB
testcase_20 AC 71 ms
71,492 KB
testcase_21 AC 271 ms
127,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(3*10**5)

mod=998244353
s=input()
n=len(s)

mex=[[1,2,1],
     [2,0,0],
     [1,0,0]]

idx=0
def calc():
  global idx
  if s[idx] in '012?':
    dp=[0]*3
    if s[idx] in '012':
      dp[int(s[idx])]=1
    else:
      dp=[1]*3
    idx+=1
    return dp
  c=s[idx+1]
  idx+=4
  dpL=calc()
  idx+=1
  dpR=calc()
  dp=[0]*3
  if c=='a' or c=='?':
    for i in range(3):
      for j in range(3):
        dp[max(i,j)]+=dpL[i]*dpR[j]
  if c=='e' or c=='?':
    for i in range(3):
      for j in range(3):
        dp[mex[i][j]]+=dpL[i]*dpR[j]
  idx+=1
  return [i%mod for i in dp]

k=int(input())
print(calc()[k])
0