結果
問題 | No.1677 mæx |
ユーザー | beet |
提出日時 | 2021-09-10 22:48:26 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 745 ms |
コンパイル使用メモリ | 70,132 KB |
実行使用メモリ | 8,024 KB |
最終ジャッジ日時 | 2023-09-02 20:01:09 |
合計ジャッジ時間 | 1,979 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,368 KB |
testcase_01 | AC | 2 ms
4,368 KB |
testcase_02 | AC | 2 ms
4,368 KB |
testcase_03 | AC | 1 ms
4,368 KB |
testcase_04 | AC | 7 ms
7,260 KB |
testcase_05 | AC | 8 ms
7,272 KB |
testcase_06 | AC | 8 ms
7,436 KB |
testcase_07 | AC | 8 ms
7,256 KB |
testcase_08 | AC | 8 ms
7,356 KB |
testcase_09 | AC | 8 ms
7,464 KB |
testcase_10 | AC | 8 ms
7,292 KB |
testcase_11 | AC | 8 ms
7,512 KB |
testcase_12 | AC | 8 ms
7,264 KB |
testcase_13 | AC | 8 ms
7,416 KB |
testcase_14 | AC | 8 ms
7,456 KB |
testcase_15 | AC | 8 ms
7,620 KB |
testcase_16 | AC | 7 ms
7,344 KB |
testcase_17 | AC | 7 ms
7,560 KB |
testcase_18 | AC | 8 ms
7,460 KB |
testcase_19 | AC | 1 ms
4,372 KB |
testcase_20 | AC | 1 ms
4,368 KB |
testcase_21 | AC | 9 ms
8,024 KB |
ソースコード
#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; }