結果

問題 No.1958 Bit Game
ユーザー tnakao0123tnakao0123
提出日時 2022-05-28 00:12:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,830 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 46,140 KB
実行使用メモリ 5,324 KB
最終ジャッジ日時 2023-10-20 21:36:20
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
5,324 KB
testcase_01 AC 70 ms
5,324 KB
testcase_02 AC 65 ms
5,324 KB
testcase_03 AC 66 ms
5,324 KB
testcase_04 AC 64 ms
5,324 KB
testcase_05 AC 67 ms
5,324 KB
testcase_06 AC 65 ms
5,324 KB
testcase_07 AC 69 ms
5,324 KB
testcase_08 AC 66 ms
5,324 KB
testcase_09 AC 68 ms
5,324 KB
testcase_10 AC 16 ms
4,348 KB
testcase_11 AC 32 ms
4,348 KB
testcase_12 AC 43 ms
4,560 KB
testcase_13 AC 33 ms
4,348 KB
testcase_14 AC 30 ms
4,348 KB
testcase_15 AC 51 ms
4,812 KB
testcase_16 AC 33 ms
4,348 KB
testcase_17 AC 56 ms
4,984 KB
testcase_18 AC 54 ms
4,964 KB
testcase_19 AC 40 ms
4,472 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 50 ms
4,852 KB
testcase_22 AC 14 ms
4,348 KB
testcase_23 AC 24 ms
4,348 KB
testcase_24 AC 46 ms
4,696 KB
testcase_25 AC 27 ms
4,348 KB
testcase_26 AC 32 ms
4,348 KB
testcase_27 AC 46 ms
4,664 KB
testcase_28 AC 39 ms
4,472 KB
testcase_29 AC 22 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1958.cc:  No.1958 Bit Game - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int BN = 18;
const int MAX_X = 1 << BN;
const int MAX_Y = 1 << BN;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

template <typename T>
struct Vec {
  T v[2];
  Vec() {}
  Vec(T a, T b) { v[0] = a, v[1] = b; }
};

template <typename T>
struct Mat {
  T v[2][2];
  Mat(): v() {}
  Mat(T a, T b, T c, T d) {
    v[0][0] = a, v[0][1] = b, v[1][0] = c, v[1][1] = d;
  }

  void init() { v[0][0] = v[0][1] = v[1][0] = v[1][1] = 0; }
  void unit() { v[0][0] = v[1][1] = 1, v[0][1] = v[1][0] = 0; }
  
  Mat operator*(const Mat &m) const {
    return Mat(v[0][0] * m.v[0][0] + v[0][1] * m.v[1][0],
	       v[0][0] * m.v[0][1] + v[0][1] * m.v[1][1],
	       v[1][0] * m.v[0][0] + v[1][1] * m.v[1][0],
	       v[1][0] * m.v[0][1] + v[1][1] * m.v[1][1]);
  }

  Vec<T> operator*(const Vec<T> &w) const {
    return Vec<T>(v[0][0] * w.v[0] + v[0][1] * w.v[1],
		  v[0][0] * w.v[0] + v[0][1] * w.v[1]);
  }

  Mat pow(int e) const {
    Mat mp; mp.unit();
    Mat ma = *this;
    while (e > 0) {
      if (e & 1) mp = mp * ma;
      ma = ma * ma;
      e >>= 1;
    }
    return mp;
  }
};

typedef Vec<mi> vec;
typedef Mat<mi> mat;

/* global variables */

int as[MAX_X], bs[MAX_Y];

/* subroutines */

int bitcnt(int m, int v[], int k) {
  int c = 0;
  for (int i = 0; i < m; i++) c += (v[i] >> k) & 1;
  return c;
}

/* main */

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 0; i < x; i++) scanf("%d", as + i);
  for (int i = 0; i < y; i++) scanf("%d", bs + i);

  mi sum = 0;
  for (int i = 0, bi = 1; i < BN; i++, bi <<= 1) {
    int ac1 = bitcnt(x, as, i), ac0 = x - ac1;
    int bc1 = bitcnt(y, bs, i), bc0 = y - bc1;

    mat ma(ac0, 0, ac1, x);
    mat mb(y, bc0, 0, bc1);
    mi v = (mb * ma).pow(n).v[1][0];
    sum += v * bi;
  }

  printf("%d\n", sum.v);
  return 0;
}
0