結果

問題 No.2071 Shift and OR
ユーザー HIcoderHIcoder
提出日時 2023-07-11 14:54:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,199 ms / 2,000 ms
コード長 2,176 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 111,896 KB
実行使用メモリ 24,600 KB
最終ジャッジ日時 2023-10-11 06:01:43
合計ジャッジ時間 13,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 7 ms
4,352 KB
testcase_03 AC 282 ms
9,576 KB
testcase_04 AC 53 ms
5,612 KB
testcase_05 AC 713 ms
16,900 KB
testcase_06 AC 75 ms
6,564 KB
testcase_07 AC 13 ms
4,352 KB
testcase_08 AC 38 ms
5,128 KB
testcase_09 AC 65 ms
6,260 KB
testcase_10 AC 91 ms
6,872 KB
testcase_11 AC 936 ms
19,348 KB
testcase_12 AC 858 ms
19,948 KB
testcase_13 AC 766 ms
16,216 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 414 ms
12,384 KB
testcase_16 AC 440 ms
12,156 KB
testcase_17 AC 815 ms
18,680 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1,199 ms
24,028 KB
testcase_20 AC 939 ms
20,456 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1,156 ms
24,600 KB
testcase_23 AC 49 ms
4,352 KB
testcase_24 AC 7 ms
4,352 KB
testcase_25 AC 23 ms
4,352 KB
testcase_26 AC 27 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 52 ms
4,348 KB
testcase_29 AC 52 ms
4,352 KB
testcase_30 AC 304 ms
10,724 KB
testcase_31 AC 68 ms
5,824 KB
testcase_32 AC 77 ms
6,068 KB
testcase_33 AC 91 ms
6,840 KB
testcase_34 AC 130 ms
7,624 KB
testcase_35 AC 175 ms
8,388 KB
testcase_36 AC 241 ms
10,440 KB
testcase_37 AC 113 ms
7,284 KB
testcase_38 AC 94 ms
6,936 KB
testcase_39 AC 68 ms
6,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


void printbit(int n){

    if(n==0) cout<<"0"<<endl; 
    vector<int> c;
    while(n>0){
        c.push_back(n%2);
        n/=2;
    }

    reverse(c.begin(),c.end());
    for(int v:c){
        cout<<v;
    }
    cout<<endl;
}

int shift(int x){
    
    return (((x%2)<<15) + (x/2));
}

int bithead(int x){
    int cnt=0;
    while(x>0){
        cnt++;
        x/=2;
    }
    return cnt;
}

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    if(N>=15){
        //鳩ノ巣原理
        //A[i]のどれかはbit1が立っているので 1を15個連続して立たせることが可能
        int ans=(1<<16)-1;
        cout<<ans<<endl;
    }else{
        //N<15


       //全探索で処理
       int ans=0;

       map<P,int> memo;

        auto dfs=[&](auto f,int idx,int num)->int{

            if(memo.count(make_pair(idx,num))) return memo[make_pair(idx,num)];

            if(idx==N){
                //ans=max(ans,num);

                //return ans;
                return num;
            }

            int res=0;
            
            for(int c=0;c<15;c++){
                res=max(res,f(f,idx+1,num|A[idx]));
                A[idx]=shift(A[idx]);
            }

            return memo[make_pair(idx,num)]=res;

        };

        ans=dfs(dfs,0,0);

        cout<<ans<<endl;



        /*
        int ans=0;
        int c=15;//2^15
        for(int i=0;i<N;i++){
            
            cout<<"i="<<i<<endl;
            int n=A[i];

            while(( (n>>c)&1)==0){
                n=shift(n);
                //cout<<"n="<<n<<endl;
            }
            
            
            printbit(n);

            ans|=n;
            cout<<"ans="<<ans<<endl;
            printbit(ans);
            c--;
        }

        cout<<ans<<endl;
        */


    }
  
}
0