結果
問題 | No.2071 Shift and OR |
ユーザー |
|
提出日時 | 2022-09-17 01:06:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 2,084 ms |
コンパイル使用メモリ | 203,108 KB |
最終ジャッジ日時 | 2025-02-07 10:54:06 |
ジャッジサーバー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; } vector dp(n + 1, vector<int>(1 << 16)); dp[0][0] = 1; for (int i = 0; i < n; i++) { set<int> seen; int x = A[i]; while (!seen.count(x)) { seen.insert(x); x = x / 2 + ((x % 2) << 15); } for (int mask = 0; mask < (1 << 16); mask++) { if (dp[i][mask]) { dp[i + 1][mask] = 1; for (int a : seen) { dp[i + 1][mask | a] = 1; } } } } int ans = 0; for (int mask = 0; mask < (1 << 16); mask++) { if (dp[n][mask]) { ans = max(ans, mask); } } cout << ans << '\n'; return 0; }