結果

問題 No.2279 OR Insertion
ユーザー miscalc
提出日時 2023-04-21 10:39:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 198,992 KB
最終ジャッジ日時 2025-02-12 10:52:38
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
  int N;
  string S;
  cin >> N >> S;

  mint ans = 0;
  for (int k = 0; k < N; k++)
  {
    /* 愚直  dp[i] := i 文字目まで見たとき、2^k の位がどれも立って**いない**仕切りの入れ方
    vector<mint> dp(N + 1, 0);
    dp.at(0) = 1;
    if (i - k < 0 || S.at(i - k) == '0')
    {
      for (ll j = 0; j <= i; j++)
        dp.at(i + 1) += dp.at(j);
    }
    else
    {
      for (ll j = i - k + 1; j <= i; j++)
        dp.at(i + 1) += dp.at(j);
    }
    */
    vector<mint> dp(N + 1, 0);  // 上の dp の累積和をとったもの
    dp.at(0) = 1;
    for (int i = 0; i < N; i++)
    {
      if (i - k < 0 || S.at(i - k) == '0')
        dp.at(i + 1) = 2 * dp.at(i);
      else
        dp.at(i + 1) = 2 * dp.at(i) - dp.at(i - k);
    }
    ans += (mint(2).pow(N - 1) - (dp.at(N) - dp.at(N - 1))) * mint(2).pow(k);
  }
  cout << ans.val() << endl;
}
0