結果

問題 No.5001 排他的論理和でランニング
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-03-16 23:48:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 1,500 ms
コード長 1,921 bytes
コンパイル時間 958 ms
実行使用メモリ 5,172 KB
スコア 52,428,750
最終ジャッジ日時 2020-03-12 19:39:08
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
5,172 KB
testcase_01 AC 11 ms
4,356 KB
testcase_02 AC 48 ms
4,424 KB
testcase_03 AC 40 ms
4,484 KB
testcase_04 AC 57 ms
5,024 KB
testcase_05 AC 22 ms
4,576 KB
testcase_06 AC 33 ms
4,644 KB
testcase_07 AC 36 ms
4,496 KB
testcase_08 AC 117 ms
5,012 KB
testcase_09 AC 49 ms
4,248 KB
testcase_10 AC 47 ms
4,348 KB
testcase_11 AC 64 ms
4,344 KB
testcase_12 AC 20 ms
4,280 KB
testcase_13 AC 93 ms
5,120 KB
testcase_14 AC 32 ms
4,648 KB
testcase_15 AC 30 ms
4,272 KB
testcase_16 AC 30 ms
4,344 KB
testcase_17 AC 47 ms
4,292 KB
testcase_18 AC 32 ms
4,548 KB
testcase_19 AC 23 ms
4,348 KB
testcase_20 AC 40 ms
4,380 KB
testcase_21 AC 40 ms
4,356 KB
testcase_22 AC 9 ms
4,388 KB
testcase_23 AC 8 ms
4,208 KB
testcase_24 AC 20 ms
4,212 KB
testcase_25 AC 44 ms
4,444 KB
testcase_26 AC 35 ms
4,496 KB
testcase_27 AC 23 ms
4,288 KB
testcase_28 AC 43 ms
4,540 KB
testcase_29 AC 58 ms
4,444 KB
testcase_30 AC 47 ms
4,284 KB
testcase_31 AC 70 ms
4,664 KB
testcase_32 AC 29 ms
4,272 KB
testcase_33 AC 75 ms
5,044 KB
testcase_34 AC 62 ms
4,996 KB
testcase_35 AC 48 ms
4,456 KB
testcase_36 AC 61 ms
4,928 KB
testcase_37 AC 36 ms
4,576 KB
testcase_38 AC 41 ms
4,268 KB
testcase_39 AC 28 ms
4,496 KB
testcase_40 AC 38 ms
4,288 KB
testcase_41 AC 16 ms
4,268 KB
testcase_42 AC 111 ms
4,248 KB
testcase_43 AC 27 ms
4,272 KB
testcase_44 AC 47 ms
4,752 KB
testcase_45 AC 63 ms
4,812 KB
testcase_46 AC 56 ms
4,432 KB
testcase_47 AC 24 ms
4,404 KB
testcase_48 AC 34 ms
4,264 KB
testcase_49 AC 47 ms
4,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cassert>
#include<cstring>
#include<iostream>
#include<random>
#include<set>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int THRESH2=40;
const int THRESH=10000;

const int M=110000;
int idx[M],occ[M];

vi solve(int n,int m,vi a){
  vi ans;
  int opt=0;
  int time2=THRESH2;
  mt19937 mt;
  while(time2>0&&opt<0xfffff){
    memset(idx,0,sizeof(idx));
    memset(occ,0,sizeof(occ));
    int x=0;
    rep(i,m){
      int v;
      do{
	v=mt()%n;
      }while(occ[v]);
      x^=a[v];
      idx[i]=v;
      occ[v]=true;
    }
    int time=THRESH;
    int pos=0;
    while(time>0&&x<0xfffff){
      //cerr<<"time="<<time<<" x="<<x<<endl;
      pii ma(-1,-1);
      rep(i,n){
	if(!occ[i]){
	  int diff=a[i]^a[idx[pos]];
	  ma=max(ma,pii(diff^x,i));
	}
      }
      if(x>ma.first){
	pos=(pos+1)%m;
	time--;
	continue;
      }
      int ind=ma.second;
      occ[idx[pos]]=0;
      occ[ind]=1;
      x^=a[ind]^a[idx[pos]];
      idx[pos]=ind;
      pos=(pos+1)%m;
      time--;
    }
    opt=max(opt,x);
    time2--;
  }
  int val=0;
  rep(i,m){
    ans.push_back(a[idx[i]]);
    val^=a[idx[i]];
  }
  return ans;
}

#if 0
int main(void) {
  int n=100000;
  rep(seed,1000){
    if(seed%10==0)cerr<<seed<<endl;
    mt19937 mt(seed);
    vi a(n);
    set<int> occ;
    rep(i,n){
      int v;
      do{
	v=mt()%1000000+1;
      }while(occ.count(v));
      a[i]=v;
      occ.insert(v);
    }
    int m=mt()%n+1;
    vi ans=solve(n,m,a);
    int sc=0;
    rep(i,m)sc^=ans[i];
    if(sc!=0xfffff){
      cout<<"seed="<<seed<<endl;
      cout<<"m="<<m<<endl;
      cout<<"score="<<sc<<" (hex:"<<hex<<sc<<")"<<dec<<endl;
    }
  }
}
#else
int main(){
  int n,m;
  cin>>n>>m;
  vi a(n);
  rep(i,n)cin>>a[i];
  vi ans=solve(n,m,a);
  rep(i,m){
    cout<<ans[i]<<(i==m-1?"\n":" ");
  }
}
#endif
0