結果

問題 No.2219 Re:010
ユーザー rabimearabimea
提出日時 2023-02-17 21:27:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 200,828 KB
実行使用メモリ 9,820 KB
最終ジャッジ日時 2023-09-26 18:33:34
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 47 ms
8,948 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 38 ms
7,744 KB
testcase_06 AC 10 ms
4,656 KB
testcase_07 AC 23 ms
6,136 KB
testcase_08 AC 45 ms
8,752 KB
testcase_09 AC 43 ms
8,620 KB
testcase_10 AC 33 ms
7,272 KB
testcase_11 AC 28 ms
6,604 KB
testcase_12 AC 28 ms
6,716 KB
testcase_13 AC 55 ms
9,792 KB
testcase_14 AC 55 ms
9,740 KB
testcase_15 AC 54 ms
9,752 KB
testcase_16 AC 55 ms
9,756 KB
testcase_17 AC 55 ms
9,804 KB
testcase_18 AC 10 ms
9,768 KB
testcase_19 AC 12 ms
9,760 KB
testcase_20 AC 85 ms
9,820 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 2e5 + 11;
ll pre[2][N], suf[2][N];

int main() {
	ios::sync_with_stdio(0);
	string s; cin >> s;
	int n = s.size();
	s = '#' + s;
	int q = count(s.begin(), s.end(), '?');
	
	for(int i = 1; i <= n; i ++) {
		pre[0][i] = pre[0][i - 1] + (s[i] == '0');
		pre[1][i] = pre[1][i - 1] + (s[i] == '?');
	}
	for(int i = n; i >= 1; i --) {
		suf[0][i] = suf[0][i + 1] + (s[i] == '0');
		suf[1][i] = suf[1][i + 1] + (s[i] == '?');
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i ++)
		if(s[i] != '0') {
			int u = (s[i] == '?');
			for(int x : {0, 1})
				for(int y : {0, 1}) if(u + x + y <= q) {
					ans += pre[x][i - 1] * suf[y][i + 1] % mod * qpow(2, q - u - x - y);
					ans %= mod;
				}
		}
	
	cout << ans << '\n';
}

0