結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

bool dp[22][1<<16];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A;
    for(int i=0;i<N;i++){
        int x;cin>>x;
        if(x){
            A.push_back(x);
        }
    }
    N=si(A);
    if(N>=16){
        cout<<(1<<16)-1<<endl;
        return 0;
    }
    
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        int x=A[i];
        for(int j=0;j<(1<<16);j++){
            for(int k=0;k<16;k++){
                dp[i+1][j|x]|=dp[i][j];
                x=(x/2)+((x&1)<<15);
            }
        }
    }
    
    for(int i=(1<<16)-1;i>=0;i--){
        if(dp[N][i]){
            cout<<i<<endl;
            return 0;
        }
    }
}
0