結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-10 22:23:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,397 bytes |
| コンパイル時間 | 662 ms |
| コンパイル使用メモリ | 71,572 KB |
| 実行使用メモリ | 11,808 KB |
| 最終ジャッジ日時 | 2024-06-12 00:59:42 |
| 合計ジャッジ時間 | 4,151 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | TLE * 1 -- * 17 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int mex(int a, int b){
if(a > b) swap(a, b);
if(a > 0) return 0;
if(b == 1) return 2;
return 1;
}
vector<ll> rec(int l, int r, string &s){
vector<ll> res(3);
if(r - l == 1){
if(s[l] == '?'){
for(int k = 0; k < 3; k++) res[k]++;
}
else res[s[l] - '0']++;
}
else{
int h = 0;
vector<ll> p, q;
for(int i = l + 4; i < r; i++){
if(s[i] == '(') h++;
if(s[i] == ')') h--;
if(s[i] == ',' && h == 0){
p = rec(l + 4, i, s), q = rec(i + 1, r - 1, s);
break;
}
}
if(s[1] != 'a'){
for(int a = 0; a < 3; a++){
for(int b = 0; b < 3; b++){
int c = mex(a, b);
res[c] = (res[c] + p[a] * q[b]) % MOD;
}
}
}
if(s[1] != 'e'){
for(int a = 0; a < 3; a++){
for(int b = 0; b < 3; b++){
int c = max(a, b);
res[c] = (res[c] + p[a] * q[b]) % MOD;
}
}
}
}
return res;
}
int main()
{
string s;
int k;
cin >> s >> k;
vector<ll> ans = rec(0, (int)s.size(), s);
cout << ans[k] << endl;
}