結果
問題 | No.1677 mæx |
ユーザー | titia |
提出日時 | 2021-09-10 23:31:29 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,096 bytes |
コンパイル時間 | 382 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 305,340 KB |
最終ジャッジ日時 | 2024-06-12 04:39:40 |
合計ジャッジ時間 | 4,276 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
63,484 KB |
testcase_01 | AC | 45 ms
55,500 KB |
testcase_02 | AC | 45 ms
55,844 KB |
testcase_03 | AC | 39 ms
53,148 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
ソースコード
import sys input = sys.stdin.readline sys.setrecursionlimit(2*10**5) S=input().strip() K=int(input()) mod=998244353 if len(S)==1: x=int(S) if K==x: print(1) else: print(0) exit() from functools import lru_cache @lru_cache(maxsize=None) def calc(S,x): #print(S,x) if len(S)==1: if S=="?": return 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:3]=="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:3]=="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 + calc(T,0)*calc(U,2)%mod + calc(T,2)*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 + calc(T,0)*calc(U,2)%mod + calc(T,2)*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)