結果

問題 No.5001 排他的論理和でランニング
ユーザー tecchaxn
提出日時 2018-03-16 23:55:05
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 314 ms / 1,500 ms
コード長 960 bytes
コンパイル時間 1,238 ms
実行使用メモリ 5,384 KB
スコア 52,428,685
最終ジャッジ日時 2020-03-12 19:40:50
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

//-----------------------------------------------------------------------

signed main()
{   
    int N,M; cin>>N>>M;
    vector<int> a(N);
    REP(i,N){
        cin>>a[i];
    }
    sort(ALL(a));

    vector<int> ans(M);
    int maxVal=-1;

    for(int c=0;c<100;c++)
    {
        int sum=0;
        REP(i,M) sum^=a[i];
        if(sum>maxVal){
            maxVal=sum;
            REP(i,M) ans[i]=a[i];
        }

        for(int i=1;i<N-M+1;i++){
            sum^=a[i-1];
            sum^=a[i+M-1];
            if(sum>maxVal){
                maxVal=sum;
                REP(j,M) ans[j]=a[i+j];
            }
        }

        random_device seed_gen;
        mt19937 engine(seed_gen());
        shuffle(ALL(a),engine);
    }

    REP(i,M){
        if(i) cout<<' ';
        cout<<ans[i];
    }
    cout<<endl;

}
0