結果
問題 | No.2219 Re:010 |
ユーザー | shinchan |
提出日時 | 2023-02-17 22:03:04 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,916 bytes |
コンパイル時間 | 2,148 ms |
コンパイル使用メモリ | 203,508 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 13:14:49 |
合計ジャッジ時間 | 2,848 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=998244353, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; ///////modint struct mint { ll x; // typedef long long ll; 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; } // for prime mod 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;} }; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s; cin >> s; vector dp(3, mint(0)); dp[0] = mint(1); mint ans = mint(0); all(c, s) { if(c == '0') { dp[1] += dp[0]; ans += dp[2]; } else if(c == '1') { dp[2] += dp[1]; } else { vector nx(3, mint(0)); rep(j, 3) nx[j] += dp[j] * mint(2); ans += ans; ans += dp[2]; nx[2] += dp[1]; nx[1] += dp[0]; swap(nx, dp); } } cout <<ans.x << endl; return 0; }