結果

問題 No.2171 OR Assignment
ユーザー 👑 chro_96chro_96
提出日時 2022-12-23 02:26:25
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 302 ms / 3,500 ms
コード長 1,222 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 29,408 KB
実行使用メモリ 50,332 KB
最終ジャッジ日時 2023-08-11 13:32:22
合計ジャッジ時間 6,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
50,328 KB
testcase_01 AC 15 ms
50,244 KB
testcase_02 AC 19 ms
50,152 KB
testcase_03 AC 13 ms
50,220 KB
testcase_04 AC 14 ms
50,288 KB
testcase_05 AC 14 ms
50,260 KB
testcase_06 AC 13 ms
50,304 KB
testcase_07 AC 13 ms
50,224 KB
testcase_08 AC 14 ms
50,272 KB
testcase_09 AC 15 ms
50,256 KB
testcase_10 AC 14 ms
50,256 KB
testcase_11 AC 13 ms
50,228 KB
testcase_12 AC 302 ms
50,304 KB
testcase_13 AC 301 ms
50,224 KB
testcase_14 AC 300 ms
50,264 KB
testcase_15 AC 139 ms
50,228 KB
testcase_16 AC 158 ms
50,168 KB
testcase_17 AC 169 ms
50,228 KB
testcase_18 AC 183 ms
50,252 KB
testcase_19 AC 184 ms
50,252 KB
testcase_20 AC 199 ms
50,160 KB
testcase_21 AC 198 ms
50,284 KB
testcase_22 AC 209 ms
50,212 KB
testcase_23 AC 276 ms
50,224 KB
testcase_24 AC 268 ms
50,280 KB
testcase_25 AC 250 ms
50,252 KB
testcase_26 AC 234 ms
50,304 KB
testcase_27 AC 221 ms
50,172 KB
testcase_28 AC 227 ms
50,292 KB
testcase_29 AC 231 ms
50,332 KB
testcase_30 AC 299 ms
50,156 KB
testcase_31 AC 187 ms
50,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int a = 0;
  
  int res = 0;
  
  long long dp[200001][31] = {};
  long long mod_num = 998244353LL;
  
  int prev[30] = {};
  
  res = scanf("%d", &n);
  
  dp[0][30] = 1LL;
  for (int i = 0; i < n; i++) {
    int prev_sort[31][2] = {};
    res = scanf("%d", &a);
    for (int j = 0; j < 30; j++) {
      if ((a&(1<<j)) > 0) {
        dp[i+1][j] = dp[i][30];
        prev[j] = i+1;
      } else {
        dp[i+1][j] = dp[i][j];
      }
      prev_sort[j][0] = prev[j];
      prev_sort[j][1] = j;
    }
    prev_sort[30][0] = -1;
    qsort(prev_sort, 31, sizeof(int)*2, cmp_int);
    dp[i+1][30] = 0LL;
    for (int j = 0; j < 30; j++) {
      if (prev_sort[j][0] != prev_sort[j+1][0]) {
        dp[i+1][30] += dp[i+1][prev_sort[j+1][1]];
        dp[i+1][30] %= mod_num;
      }
      dp[i+1][prev_sort[j+1][1]] = dp[i+1][30];
    }
    if (a == 0) {
      dp[i+1][30] += dp[i][30];
      dp[i+1][30] %= mod_num;
    }
  }
  
  printf("%lld\n", dp[n][30]);
  return 0;
}

0