結果
問題 | No.5001 排他的論理和でランニング |
ユーザー |
![]() |
提出日時 | 2018-03-16 23:41:23 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,838 bytes |
コンパイル時間 | 959 ms |
実行使用メモリ | 9,248 KB |
スコア | 9,437,175 |
最終ジャッジ日時 | 2020-03-12 19:37:08 |
ジャッジサーバーID (参考情報) |
judge8 / |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 TLE * 1 -- * 40 |
ソースコード
#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=10; 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; while(time2>0&&opt<0xfffff){ memset(idx,0,sizeof(idx)); memset(occ,0,sizeof(occ)); int x=0; rep(i,m){ x^=a[i]; idx[i]=i; occ[i]=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); } 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