結果

問題 No.1189 Sum is XOR
ユーザー EbishuEbishu
提出日時 2020-07-31 00:33:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,381 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 93,320 KB
実行使用メモリ 15,528 KB
最終ジャッジ日時 2023-09-23 00:27:01
合計ジャッジ時間 7,537 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;
using lint = int64_t;

constexpr lint mod = 998244353;
		
inline bool f(int x, int y) { return x + y == (x xor y); }

lint inv(lint x) {
	lint res = 1, expo = mod - 2;
	while (expo > 0) {
		if (expo & 1) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		expo >>= 1;
	}
	return res;
}

lint solve(int n, int k, const vector<int>& a) {
	lint res = 0;
	if (k == 2) {
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (f(a[i], a[j])) res++;
			}
		}
		return res;
	}
	else {
		vector<unordered_map<int, lint>>mp_vec(k - 2);
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (f(a[i], a[j])) mp_vec[0][a[i] xor a[j]]++;
			}
		}
		for (int i = 0; i < k - 2; i++) {
			for (auto [key, value] : mp_vec[i]) {
				for (int e : a) {
					if (f(key, e)) {
						if (i < k - 3) {
							mp_vec[i + 1][key xor e] += value;
							mp_vec[i + 1][key xor e] %= mod;
						}
						else {
							res += value;
							res %= mod;
						}
					}
				}
			}
			if (i < k - 3 && mp_vec[i + 1].empty()) return 0;
		}
		lint fact = 1;
		for (lint i = 3; i <= k; i++) {
			fact *= i; fact %= mod;
		}
		return res * inv(fact) % mod;
	}
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	for (int& e : A) cin >> e;
	cout << solve(N, K, A) << endl;
}
0