結果
問題 | No.1677 mæx |
ユーザー |
![]() |
提出日時 | 2021-09-10 22:48:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 913 ms |
コンパイル使用メモリ | 68,668 KB |
最終ジャッジ日時 | 2025-01-24 11:56:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#include <iostream> #include <cassert> using namespace std; const int MOD = 998244353; const int MAX = 2e5+10; int ans[3][MAX]={}; int mex(int i,int j){ if(i!=0 and j!=0) return 0; if(i!=1 and j!=1) return 1; return 2; } void number(string& s,int& p){ if(isdigit(s[p])){ ans[s[p]-'0'][p]=1; }else{ assert(s[p]=='?'); ans[0][p]=ans[1][p]=ans[2][p]=1; } p++; } void expression(string& s,int& p){ if(s[p]!='m'){ number(s,p); return; } int x=p; assert(s[p]=='m' and s[p+2]=='x' and s[p+3]=='('); char c=s[p+1]; assert(c=='a' or c=='e' or c=='?'); p+=4; int y=p; expression(s,p); assert(s[p]==','); p+=1; int z=p; expression(s,p); assert(s[p]==')'); p+=1; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(c=='a' or c=='?'){ ans[max(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD; ans[max(i,j)][x]%=MOD; } if(c=='e' or c=='?'){ ans[mex(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD; ans[mex(i,j)][x]%=MOD; } } } } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; int p=0; expression(s,p); int k; cin>>k; cout<<ans[k][0]<<endl; return 0; }