結果
| 問題 | No.2071 Shift and OR | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-12-12 22:44:56 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 65 ms / 2,000 ms | 
| コード長 | 758 bytes | 
| コンパイル時間 | 719 ms | 
| コンパイル使用メモリ | 67,072 KB | 
| 最終ジャッジ日時 | 2025-02-09 10:37:07 | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[200005];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    if(n >= 16)
    {
        cout << (1 << 16) - 1 << endl;
        return 0;
    }
    bool dp[70000]{0};
    dp[0] = 1;
    for(int i = 0; i < n; i++)
    {
        bool d[70000]{0};
        for(int c = 0; c < 16; c++)
        {
            for(int s = 0; s < (1 << 16); s++)
            {
                d[s | a[i]] |= dp[s];
            }
            a[i] = ((a[i] << 1) & ((1 << 16) - 1)) + (a[i] >> 15);
        }
        swap(dp, d);
    }
    for(int s = (1 << 16) - 1; s >= 0; s--)
    {
        if(dp[s])
        {
            cout << s << endl;
            break;
        }
    }
}
            
            
            
        