結果
| 問題 |
No.183 たのしい排他的論理和(EASY)
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-10-20 01:15:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4,326 ms / 5,000 ms |
| コード長 | 1,404 bytes |
| コンパイル時間 | 2,808 ms |
| コンパイル使用メモリ | 286,372 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-20 01:15:46 |
| 合計ジャッジ時間 | 27,303 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// 汎用 DP 関数
template <typename T, typename X>
vector<T> accum_dp(
const vector<X>& xs,
function<vector<pair<int, T>>(int, T, X)> f,
function<T(T, T)> op,
T e,
int size,
const vector<pair<int, T>>& init,
bool is_reset = true
) {
vector<T> dp(size, e);
for (auto [i, v] : init) dp[i] = v;
for (auto x : xs) {
vector<T> pp = is_reset ? vector<T>(size, e) : dp; // dp.copy() の代わり
swap(dp, pp);
for (int i = 0; i < size; i++) {
for (auto [p, v] : f(i, pp[i], x)) {
if (p < 0 || p >= size) continue;
dp[p] = op(dp[p], v);
}
}
}
return dp;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
// f: 遷移関数
auto next_func = [](int i, bool v, int x) -> vector<pair<int, bool>> {
if (!v) return {};
return {{i ^ x, true}};
};
// op: 集約演算
auto op = [](bool a, bool b) -> bool {
return a || b;
};
int size = 1 << 15;
vector<pair<int, bool>> init = {{0, true}};
auto dp = accum_dp<bool, int>(A, next_func, op, false, size, init, false);
int ans = count(dp.begin(), dp.end(), true);
cout << ans << "\n";
return 0;
}
norioc