結果

問題 No.2219 Re:010
ユーザー stoqstoq
提出日時 2023-01-29 06:43:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 674 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 203,568 KB
実行使用メモリ 5,148 KB
最終ジャッジ日時 2023-09-11 15:34:28
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 9 ms
4,704 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,436 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 9 ms
4,548 KB
testcase_09 AC 8 ms
4,612 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 6 ms
4,384 KB
testcase_13 AC 11 ms
5,012 KB
testcase_14 AC 10 ms
5,140 KB
testcase_15 AC 11 ms
5,148 KB
testcase_16 AC 11 ms
4,964 KB
testcase_17 AC 11 ms
5,072 KB
testcase_18 AC 9 ms
5,080 KB
testcase_19 AC 9 ms
5,080 KB
testcase_20 AC 10 ms
5,144 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 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> S0(n + 1), Sq(n + 1);
  for (int i = 0; i < n; i++) {
    S0[i + 1] = S0[i] + (s[i] == '0');
    Sq[i + 1] = Sq[i] + (s[i] == '?');
  }
  mint ans = 0;
  const mint inv2 = mint(2).inv();
  for (int i = 0; i < n; i++) {
    mint L = S0[i] + Sq[i] * inv2;
    mint R = (S0[n] - S0[i + 1]) + (Sq[n] - Sq[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(Sq[n]);
  cout << ans.val() << "\n";
}
0