結果

問題 No.2071 Shift and OR
ユーザー ripity
提出日時 2022-10-30 13:15:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 4,173 ms
コンパイル使用メモリ 251,956 KB
最終ジャッジ日時 2025-02-08 15:59:55
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
void shift(int& x) {
  x = (x>>1)+((x&1)<<15);
}
int main() {
  int N, MAX = 1<<16;
  cin >> N;
  vector<int> A(N+1);
  for( int i = 1; i <= N; i++ ) {
    cin >> A[i];
  }
  if( N >= 16 ) {
    cout << MAX-1 << endl;
  }else {
    vector<vector<int>> dp(N+1, vector<int>(MAX));
    dp[0][0] = true;
    for( int i = 1; i <= N; i++ ) {
      for( int j = 0; j < MAX; j++ ) {
        for( int k = 0; k < 16; k++ ) {
          dp[i][j|A[i]] |= dp[i-1][j];
          shift(A[i]);
        }
      }
    }
    for( int j = MAX-1; j >= 0; j-- ) {
      if( dp[N][j] ) {
        cout << j << endl;
        break;
      }
    }
  }
}
0