結果

問題 No.1958 Bit Game
ユーザー SSRSSSRS
提出日時 2022-05-27 21:29:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 176,528 KB
実行使用メモリ 5,408 KB
最終ジャッジ日時 2023-10-20 19:53:38
合計ジャッジ時間 6,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
5,408 KB
testcase_01 AC 149 ms
5,408 KB
testcase_02 AC 152 ms
5,408 KB
testcase_03 AC 146 ms
5,408 KB
testcase_04 AC 153 ms
5,408 KB
testcase_05 AC 153 ms
5,408 KB
testcase_06 AC 147 ms
5,408 KB
testcase_07 AC 152 ms
5,408 KB
testcase_08 AC 159 ms
5,408 KB
testcase_09 AC 156 ms
5,408 KB
testcase_10 AC 34 ms
4,348 KB
testcase_11 AC 72 ms
4,352 KB
testcase_12 AC 93 ms
4,616 KB
testcase_13 AC 79 ms
4,352 KB
testcase_14 AC 70 ms
4,352 KB
testcase_15 AC 113 ms
4,880 KB
testcase_16 AC 77 ms
4,352 KB
testcase_17 AC 128 ms
5,144 KB
testcase_18 AC 126 ms
4,880 KB
testcase_19 AC 89 ms
4,616 KB
testcase_20 AC 69 ms
4,352 KB
testcase_21 AC 115 ms
4,880 KB
testcase_22 AC 29 ms
4,348 KB
testcase_23 AC 55 ms
4,348 KB
testcase_24 AC 104 ms
4,616 KB
testcase_25 AC 60 ms
4,348 KB
testcase_26 AC 71 ms
4,352 KB
testcase_27 AC 102 ms
4,616 KB
testcase_28 AC 89 ms
4,616 KB
testcase_29 AC 44 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<vector<long long>> matmul(vector<vector<long long>> A, vector<vector<long long>> B){
	int N = A.size();
	vector<vector<long long>> ans(N, vector<long long>(N, 0));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			for (int k = 0; k < N; k++){
				ans[i][k] += A[i][j] * B[j][k];
				ans[i][k] %= MOD;
			}
		}
	}
	return ans;
}
vector<vector<long long>> matexp(vector<vector<long long>> A, long long b){
	int N = A.size();
	vector<vector<long long>> ans(N, vector<long long>(N, 0));
	for (int i = 0; i < N; i++){
		ans[i][i] = 1;
	}
	while (b > 0){
		if (b % 2 == 1){
			ans = matmul(ans, A);
		}
		A = matmul(A, A);
		b /= 2;
	}
	return ans;
}
int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> A(X);
  for (int i = 0; i < X; i++){
    cin >> A[i];
  }
  vector<int> B(Y);
  for (int i = 0; i < Y; i++){
    cin >> B[i];
  }
  long long ans = 0;
  for (int i = 0; i < 18; i++){
    long long cnt1 = 0;
    for (int j = 0; j < X; j++){
      if ((A[j] >> i & 1) == 1){
        cnt1++;
      }
    }
    long long cnt0 = 0;
    for (int j = 0; j < Y; j++){
      if ((B[j] >> i & 1) == 0){
        cnt0++;
      }
    }
    vector<vector<long long>> M(2, vector<long long>(2));
    M[0][0] = (cnt1 * cnt0 + (X - cnt1) * Y) % MOD;
    M[0][1] = cnt1 * (Y - cnt0) % MOD;
    M[1][0] = (cnt1 * cnt0 + (X - cnt1) * cnt0) % MOD;
    M[1][1] = (cnt1 * (Y - cnt0) + (X - cnt1) * (Y - cnt0)) % MOD;
    M = matexp(M, N);
    ans += (1 << i) * M[0][1] % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0