結果
問題 |
No.2071 Shift and OR
|
ユーザー |
|
提出日時 | 2022-09-17 01:14:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 1,942 ms |
コンパイル使用メモリ | 197,428 KB |
最終ジャッジ日時 | 2025-02-07 10:54:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } if (n > 15) { cout << (1 << 16) - 1 << '\n'; return 0; } const int N = 1 << 16; bitset<N> dp; dp.set(0, true); for (int i = 0; i < n; i++) { bitset<N> B; int x = A[i]; vector<int> seen; while (!B.test(x)) { B.set(x, true); seen.push_back(x); x = x / 2 + ((x % 2) << 15); } bitset<N> ndp; for (int mask = 0; mask < (1 << 16); mask++) { if (dp.test(mask)) { ndp.set(mask, true); for (int a : seen) { ndp.set(mask | a, true); } } } swap(dp, ndp); } int ans = 0; for (int mask = 0; mask < (1 << 16); mask++) { if (dp.test(mask)) { ans = max(ans, mask); } } cout << ans << '\n'; return 0; }