結果
問題 | No.2219 Re:010 |
ユーザー | tsugutsugu |
提出日時 | 2023-02-17 23:33:53 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 2,692 bytes |
コンパイル時間 | 1,601 ms |
コンパイル使用メモリ | 172,360 KB |
実行使用メモリ | 29,312 KB |
最終ジャッジ日時 | 2024-07-19 14:45:19 |
合計ジャッジ時間 | 2,845 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
15,360 KB |
testcase_01 | AC | 8 ms
15,232 KB |
testcase_02 | AC | 8 ms
15,360 KB |
testcase_03 | AC | 30 ms
27,264 KB |
testcase_04 | AC | 12 ms
16,384 KB |
testcase_05 | AC | 26 ms
24,576 KB |
testcase_06 | AC | 14 ms
17,536 KB |
testcase_07 | AC | 19 ms
20,992 KB |
testcase_08 | AC | 30 ms
26,496 KB |
testcase_09 | AC | 32 ms
25,984 KB |
testcase_10 | AC | 25 ms
23,552 KB |
testcase_11 | AC | 21 ms
22,016 KB |
testcase_12 | AC | 22 ms
22,144 KB |
testcase_13 | AC | 32 ms
29,312 KB |
testcase_14 | AC | 33 ms
29,312 KB |
testcase_15 | AC | 34 ms
29,184 KB |
testcase_16 | AC | 32 ms
29,312 KB |
testcase_17 | AC | 33 ms
29,184 KB |
testcase_18 | AC | 31 ms
29,184 KB |
testcase_19 | AC | 32 ms
29,312 KB |
testcase_20 | AC | 31 ms
29,184 KB |
testcase_21 | AC | 10 ms
15,232 KB |
testcase_22 | AC | 9 ms
15,232 KB |
testcase_23 | AC | 9 ms
15,104 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500044; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; int main() { string s; cin >> s; int n = s.size(); vector<vector<Mint>> dp(n + 1, vector<Mint>(4, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { dp[i + 1][j] += dp[i][j] * (s[i] == '?' ? 2 : 1); } if (s[i] == '0') { dp[i + 1][1] += dp[i][0]; dp[i + 1][3] += dp[i][2]; } if (s[i] == '1') { dp[i + 1][2] += dp[i][1]; } if (s[i] == '?') { for (int j = 0; j < 3; j++) { dp[i + 1][j + 1] += dp[i][j]; } } } cout << dp[n][3] << endl; }