結果
| 問題 | 
                            No.2071 Shift and OR
                             | 
                    
| コンテスト | |
| ユーザー | 
                             SSRS
                         | 
                    
| 提出日時 | 2022-09-16 21:25:53 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 52 ms / 2,000 ms | 
| コード長 | 803 bytes | 
| コンパイル時間 | 1,795 ms | 
| コンパイル使用メモリ | 174,164 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-21 18:22:33 | 
| 合計ジャッジ時間 | 3,451 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  if (N >= 16){
    cout << (1 << 16) - 1 << endl;
  } else {
    vector<vector<bool>> dp(N + 1, vector<bool>(1 << 16, false));
    dp[0][0] = true;
    for (int i = 0; i < N; i++){
      vector<int> B(16);
      B[0] = A[i];
      for (int j = 0; j < 15; j++){
        B[j + 1] = B[j] / 2 + ((B[j] % 2) << 15);
      }
      for (int j = 0; j < (1 << 16); j++){
        if (dp[i][j]){
          for (int k = 0; k < 16; k++){
            dp[i + 1][j | B[k]] = true;
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < (1 << 16); i++){
      if (dp[N][i]){
        ans = max(ans, i);
      }
    }
    cout << ans << endl;
  }
}
            
            
            
        
            
SSRS