結果

問題 No.2279 OR Insertion
ユーザー 👑 chro_96chro_96
提出日時 2023-04-22 01:33:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 126,924 KB
最終ジャッジ日時 2024-04-24 10:44:59
合計ジャッジ時間 7,401 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
126,848 KB
testcase_01 AC 65 ms
126,780 KB
testcase_02 AC 76 ms
126,848 KB
testcase_03 AC 70 ms
126,848 KB
testcase_04 AC 160 ms
126,840 KB
testcase_05 AC 67 ms
126,836 KB
testcase_06 AC 100 ms
126,828 KB
testcase_07 AC 98 ms
126,848 KB
testcase_08 AC 73 ms
126,848 KB
testcase_09 AC 111 ms
126,848 KB
testcase_10 AC 160 ms
126,820 KB
testcase_11 AC 73 ms
126,772 KB
testcase_12 AC 135 ms
126,848 KB
testcase_13 AC 70 ms
126,848 KB
testcase_14 AC 70 ms
126,804 KB
testcase_15 AC 102 ms
126,800 KB
testcase_16 AC 64 ms
126,856 KB
testcase_17 AC 94 ms
126,916 KB
testcase_18 AC 122 ms
126,848 KB
testcase_19 AC 145 ms
126,700 KB
testcase_20 AC 100 ms
126,720 KB
testcase_21 AC 88 ms
126,848 KB
testcase_22 AC 63 ms
126,804 KB
testcase_23 AC 64 ms
126,848 KB
testcase_24 AC 64 ms
126,824 KB
testcase_25 AC 65 ms
126,848 KB
testcase_26 AC 65 ms
126,780 KB
testcase_27 AC 63 ms
126,848 KB
testcase_28 AC 64 ms
126,824 KB
testcase_29 AC 64 ms
126,744 KB
testcase_30 AC 67 ms
126,848 KB
testcase_31 AC 64 ms
126,848 KB
testcase_32 AC 171 ms
126,848 KB
testcase_33 AC 170 ms
126,860 KB
testcase_34 AC 169 ms
126,848 KB
testcase_35 AC 170 ms
126,848 KB
testcase_36 AC 173 ms
126,848 KB
testcase_37 AC 170 ms
126,696 KB
testcase_38 AC 167 ms
126,848 KB
testcase_39 AC 166 ms
126,924 KB
testcase_40 AC 167 ms
126,832 KB
testcase_41 AC 170 ms
126,824 KB
testcase_42 AC 239 ms
126,848 KB
testcase_43 AC 229 ms
126,848 KB
testcase_44 AC 238 ms
126,768 KB
testcase_45 AC 110 ms
126,832 KB
testcase_46 AC 111 ms
126,736 KB
testcase_47 AC 112 ms
126,860 KB
testcase_48 AC 252 ms
126,848 KB
testcase_49 AC 97 ms
126,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  char s[4001] = "";
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long dp[4000][4000] = {};
  long long pow2[4000] = {};
  int cnt[4000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%s", s);
  
  if (n <= 1) {
    printf("%d\n", (int)(s[0]-'0'));
    return 0;
  }
  
  pow2[0] = 1LL;
  for (int i = 1; i < n; i++) {
    pow2[i] = (pow2[i-1]*2LL)%mod_num;
  }
  
  if (s[0] == '1') {
    dp[0][0] = 1LL;
    ans += pow2[n-2];
  }
  
  for (int i = 1; i < n; i++) {
    for (int j = i; j >= 0; j--) {
      if (s[j] == '1') {
        long long tmp = pow2[j];
        if (j > 0) {
          tmp += mod_num-dp[j-1][i-j];
        }
        dp[i][i-j] = tmp%mod_num;
        tmp *= pow2[i-j];
        tmp %= mod_num;
        if (i < n-1) {
          tmp *= pow2[n-2-i];
        }
        ans += tmp%mod_num;
      }
    }
    for (int j = 0; j < n; j++) {
      dp[i][j] += 2LL*dp[i-1][j];
      dp[i][j] %= mod_num;
    }
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0