結果

問題 No.2219 Re:010
ユーザー stoqstoq
提出日時 2022-01-26 09:01:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 205,828 KB
実行使用メモリ 5,328 KB
最終ジャッジ日時 2023-10-21 01:05:22
合計ジャッジ時間 3,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 10 ms
5,064 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 8 ms
4,800 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 10 ms
4,800 KB
testcase_09 AC 9 ms
4,800 KB
testcase_10 AC 8 ms
4,412 KB
testcase_11 AC 6 ms
4,412 KB
testcase_12 AC 7 ms
4,412 KB
testcase_13 AC 11 ms
5,328 KB
testcase_14 AC 11 ms
5,328 KB
testcase_15 AC 11 ms
5,328 KB
testcase_16 AC 11 ms
5,328 KB
testcase_17 AC 11 ms
5,328 KB
testcase_18 AC 10 ms
5,328 KB
testcase_19 AC 10 ms
5,328 KB
testcase_20 AC 10 ms
5,328 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> csum0(n + 1), csumq(n + 1);
  for (int i = 0; i < n; i++) {
    csum0[i + 1] = csum0[i] + (s[i] == '0');
    csumq[i + 1] = csumq[i] + (s[i] == '?');
  }
  mint ans = 0;
  const mint inv2 = mint(2).inv();
  for (int i = 0; i < n; i++) {
    mint L = csum0[i] + csumq[i] * inv2;
    mint R = (csum0[n] - csum0[i + 1]) + (csumq[n] - csumq[i + 1]) * inv2;
    mint E = L * R;
    if (s[i] == '0')
      E = 0;
    else if (s[i] == '?')
      E *= inv2;
    ans += E;
  }
  ans *= mint(2).pow(csumq[n]);
  cout << ans.val() << "\n";
}
0