結果
問題 |
No.1189 Sum is XOR
|
ユーザー |
![]() |
提出日時 | 2020-07-31 00:33:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,381 bytes |
コンパイル時間 | 1,110 ms |
コンパイル使用メモリ | 88,456 KB |
最終ジャッジ日時 | 2025-01-12 08:23:18 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 TLE * 18 |
ソースコード
#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; }