結果
| 問題 |
No.5001 排他的論理和でランニング
|
| ユーザー |
IL_msta
|
| 提出日時 | 2018-03-17 13:38:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 377 ms / 1,500 ms |
| コード長 | 2,525 bytes |
| コンパイル時間 | 956 ms |
| 実行使用メモリ | 7,420 KB |
| スコア | 34,220,396 |
| 最終ジャッジ日時 | 2020-03-12 20:04:44 |
|
ジャッジサーバーID (参考情報) |
judge7 / |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <ctime>
////
#include <random>//
#pragma endregion //#include
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
#pragma region
namespace RAND{
unsigned long xor128(){
static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
unsigned long t;
t=(x^(x<<11));x=y;y=z;z=w;
return( w=(w^(w>>19))^(t^(t>>8)) );
}
LL getRAND(LL P){
return ((xor128()%P)+P)%P;
}
}
#pragma endregion //乱数
///////////////////
int N,M;
int best;
int nowVal;//現在の値
vector<int> A;
vector<int> use;//使用中
vector<int> Notuse;//未使用
vector<int> bestUse;
void cal(){//一回だけ
int ret = 0;
for(int i=0;i<M;++i){
ret ^= A[ use[i] ];
}
best = max(best,ret);
bestUse = use;
nowVal = ret;
}
void output(){
bool flag = false;
for(int i=0;i<M;++i){
if(flag){
cout << ' ';
}
cout << A[ use[i] ];
flag = true;
}
cout << endl;
}
void solve(){
cin>>N>>M;
A = vector<int>(N);
for(int i=0;i<N;++i){
cin>>A[i];
}
sort(A.begin(),A.end());
use = vector<int>(M);
Notuse = vector<int>(N-M);
for(int i=0;i<N;++i){
if(i<M){
use[i] = i;
}else{
Notuse[i-M] = i;
}
}
if( N==M ){
output();
return;
}
int count = 8000000;
while(count--){
//cout << count << " " << best << "\r";
//未使用を一つ選ぶ
int ter0 = RAND::getRAND(N-M);
//使用中を一つ選ぶ
int ter1 = RAND::getRAND(M);
//交換
int val = A[ Notuse[ter0] ]^A[ use[ter1] ];
nowVal ^= val;
if( best - nowVal < (count>>8) ){
swap( Notuse[ter0],use[ter1] );
if( best -nowVal < 0 ){
best = nowVal;
bestUse = use;
}
}else{//戻す
nowVal ^= val;
}
}
output();
}
#pragma region main
signed main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//小数を10進数表示
cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別
solve();
}
#pragma endregion //main()
IL_msta