結果

問題 No.2071 Shift and OR
ユーザー shoshoshom
提出日時 2022-09-17 01:11:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 199,896 KB
最終ジャッジ日時 2025-02-07 10:54:15
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++) {
    set<int> seen;
    int x = A[i];
    while (!seen.count(x)) {
      seen.insert(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;
}
0