結果

問題 No.2279 OR Insertion
ユーザー SSRSSSRS
提出日時 2023-04-21 21:55:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 166,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 08:03:52
合計ジャッジ時間 7,330 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 22 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 158 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 63 ms
5,376 KB
testcase_07 AC 69 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 90 ms
5,376 KB
testcase_10 AC 153 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 120 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 76 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 61 ms
5,376 KB
testcase_18 AC 105 ms
5,376 KB
testcase_19 AC 137 ms
5,376 KB
testcase_20 AC 70 ms
5,376 KB
testcase_21 AC 51 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 174 ms
5,376 KB
testcase_33 AC 173 ms
5,376 KB
testcase_34 AC 174 ms
5,376 KB
testcase_35 AC 174 ms
5,376 KB
testcase_36 AC 173 ms
5,376 KB
testcase_37 AC 174 ms
5,376 KB
testcase_38 AC 175 ms
5,376 KB
testcase_39 AC 174 ms
5,376 KB
testcase_40 AC 174 ms
5,376 KB
testcase_41 AC 174 ms
5,376 KB
testcase_42 AC 172 ms
5,376 KB
testcase_43 AC 172 ms
5,376 KB
testcase_44 AC 172 ms
5,376 KB
testcase_45 AC 173 ms
5,376 KB
testcase_46 AC 174 ms
5,376 KB
testcase_47 AC 173 ms
5,376 KB
testcase_48 AC 173 ms
5,376 KB
testcase_49 AC 174 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  for (int i = 0; i < N; i++){
    S += '0';
  }
  vector<long long> POW(N);
  POW[0] = 1;
  for (int i = 0; i < N - 1; i++){
    POW[i + 1] = POW[i] * 2 % MOD;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    vector<long long> dp(N + 1, 0);
    dp[0] = 1;
    vector<long long> imos(N + 2, 0);
    for (int j = 0; j < N; j++){
      dp[j] += imos[j];
      dp[j] %= MOD;
      imos[j + 1] += imos[j];
      imos[j + 1] %= MOD;
      if (S[j + i] == '0'){
        imos[j + 1] += dp[j];
        imos[j + 1] %= MOD;
        imos[N + 1] += MOD - dp[j];
        imos[N + 1] %= MOD;
      } else {
        imos[j + 1] += dp[j];
        imos[j + 1] %= MOD;
        imos[min(N, j + i) + 1] += MOD - dp[j];
        imos[min(N, j + i) + 1] %= MOD;
      }
    }
    dp[N] += imos[N];
    dp[N] %= MOD;
    ans += POW[i] * (POW[N - 1] - dp[N] + MOD) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0