結果

問題 No.206 数の積集合を求めるクエリ
ユーザー akakimidoriakakimidori
提出日時 2019-04-27 01:55:04
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 29,876 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-17 05:02:26
合計ジャッジ時間 8,117 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 0 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef int32_t i32;
typedef uint64_t u64;

i32 popcnt (u64 n) {
  n = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555);
  n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333);
  n = (n & 0x0F0F0F0F0F0F0F0F) + ((n >> 4) & 0x0F0F0F0F0F0F0F0F);
  n = (n & 0x00FF00FF00FF00FF) + ((n >> 8) & 0x00FF00FF00FF00FF);
  n = (n & 0x0000FFFF0000FFFF) + ((n >> 16) & 0x0000FFFF0000FFFF);
  return (n + (n >> 32)) & 0x00000000FFFFFFFF;
}

void run (void) {
  i32 l, m, n;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &m, &n);
  const i32 f = 8 * sizeof (u64);
  i32 len = (n + 1 + f - 1) / f;
  u64 *a = (u64 *) calloc (len, sizeof (u64));
  u64 *b = (u64 *) calloc (len, sizeof (u64));
  while (l--) {
    i32 v;
    scanf ("%" SCNi32, &v);
    a[v / f] |= 1 << (v % f);
  }
  while (m--) {
    i32 v;
    scanf ("%" SCNi32, &v);
    b[v / f] |= 1 << (v % f);
  }
  i32 q;
  scanf ("%" SCNi32, &q);
  for (i32 i = 0; i < q; ++i) {
    i32 ans = 0;
    for (i32 j = 0; j < len; ++j) {
      ans += popcnt (a[j] & b[j]);
    }
    printf ("%" PRIi32 "\n", ans);
    for (i32 j = len - 1; j > 0; --j) {
      b[j] = (b[j] << 1) | (b[j - 1] >> (f - 1));
    }
    b[0] <<= 1;
  }
  
}

int main (void) {
  run();
  return 0;
}
0