結果
問題 | No.1677 mæx |
ユーザー | titia |
提出日時 | 2021-09-10 23:18:15 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,847 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 82,004 KB |
実行使用メモリ | 339,852 KB |
最終ジャッジ日時 | 2024-06-12 03:57:49 |
合計ジャッジ時間 | 14,350 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
60,168 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 39 ms
52,692 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | TLE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | AC | 38 ms
52,496 KB |
testcase_20 | AC | 38 ms
54,104 KB |
testcase_21 | TLE | - |
ソースコード
import sys input = sys.stdin.readline S=input().strip() K=int(input()) mod=998244353 if len(S)==1: x=int(S) if K==x: print(1) else: print(0) exit() def calc(S,x): if len(S)==1: y=int(S) if y==x: return 1 else: return 0 now=0 for i in range(4,len(S)): if S[i]=="(": now+=1 elif S[i]==")": now-=1 elif S[i]=="," and now==0: kom=i break T=S[4:kom] U=S[kom+1:-1] if S[0:2]=="max": if x==0: return calc(T,0)*calc(U,0)%mod elif x==1: return (calc(T,0)*calc(U,1)%mod+calc(T,1)*calc(U,0)%mod+calc(T,1)*calc(U,1)%mod)%mod else: return (calc(T,0)*calc(U,2)%mod+calc(T,1)*calc(U,2)%mod+calc(T,2)*calc(U,0)%mod+calc(T,2)*calc(U,1)%mod+calc(T,2)*calc(U,2)%mod)%mod elif S[0:2]=="mex": if x==0: return calc(T,1)*calc(U,1)%mod + calc(T,1)*calc(U,2)%mod +calc(T,2)*calc(U,1)%mod + calc(T,2)*calc(U,2)%mod elif x==1: return calc(T,0)*calc(U,0)%mod else: return (calc(T,0)*calc(U,1)%mod+calc(T,1)*calc(U,0)%mod)%mod else: if x==0: return calc(T,0)*calc(U,0)%mod +calc(T,1)*calc(U,1)%mod + calc(T,1)*calc(U,2)%mod +calc(T,2)*calc(U,1)%mod + calc(T,2)*calc(U,2)%mod elif x==1: return (calc(T,0)*calc(U,1)%mod+calc(T,1)*calc(U,0)%mod+calc(T,1)*calc(U,1)%mod)%mod + calc(T,0)*calc(U,0)%mod else: return (calc(T,0)*calc(U,2)%mod+calc(T,1)*calc(U,2)%mod+calc(T,2)*calc(U,0)%mod+calc(T,2)*calc(U,1)%mod+calc(T,2)*calc(U,2)%mod)%mod + (calc(T,0)*calc(U,1)%mod+calc(T,1)*calc(U,0)%mod)%mod print(calc(S,K)%mod)