結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
norikame
|
| 提出日時 | 2021-09-10 23:13:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,458 bytes |
| コンパイル時間 | 2,368 ms |
| コンパイル使用メモリ | 196,672 KB |
| 最終ジャッジ日時 | 2025-01-24 12:18:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 TLE * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()
const ll mod = 998244353LL;
struct mint {
ll x;
mint(ll x=0) : x((x%mod+mod)%mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
inline int mex(int a, int b) {
int res = 0;
while (res==a || res==b) ++res;
return res;
}
string s;
pair<mint, int> calc(int id, int k) {
pair<mint, int> res = { mint(0), id };
if (id >= (int)(s.length())) return res;
if (s[id] == 'm') {
int nid1 = id + 4;
vector<pair<mint, int>> res1(3), res2(3);
rep(i, 3) res1[i] = calc(nid1, i);
int nid2 = res1.front().second + 2;
rep(i, 3) res2[i] = calc(nid2, i);
res.second = res2.front().second + 1;
if (s[id+1]=='a' || s[id+1]=='?') rep(i, 3) rep(j, 3) if (max(i, j) == k) res.first += res1[i].first * res2[j].first;
if (s[id+1]=='e' || s[id+1]=='?') rep(i, 3) rep(j, 3) if (mex(i, j) == k) res.first += res1[i].first * res2[j].first;
}
else {
if (s[id] == '?') res.first = 1;
else if (s[id]-'0' == k) res.first = 1;
else res.first = 0;
}
return res;
}
int main() {
int k;
cin >> s >> k;
cout << calc(0, k).first << endl;
return 0;
}
norikame