結果
問題 | No.5001 排他的論理和でランニング |
ユーザー | どらら |
提出日時 | 2018-03-17 14:05:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,449 bytes |
コンパイル時間 | 1,517 ms |
実行使用メモリ | 7,424 KB |
スコア | 0 |
最終ジャッジ日時 | 2020-03-12 20:07:05 |
ジャッジサーバーID (参考情報) |
judge8 / |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
ソースコード
#include <bits/stdc++.h> #include <sys/time.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; unsigned int xor128(){ static unsigned int x=123456789, y=362436069, z=521288629, w=88675123; unsigned int t; t=(x^(x<<11)); x=y; y=z; z=w; return w=(w^(w>>19))^(t^(t>>8)); } class Timer { double start_time; double getNow(){ struct timeval t; gettimeofday(&t, NULL); return t.tv_sec + t.tv_usec * 1e-6; } public: void start(){ start_time = getNow(); } double getSec(){ return getNow()-start_time; } }; Timer timer; vector<int> solve(const vector<int>& v, int N, int M){ bitset<100005> w; int score = 0; rep(i,M){ w[i] = 1; score ^= v[i]; } int t = 0; while(timer.getSec()<1.0){ ///* for(int i=22; i>=0; i--){ if((score>>i)&1) cout << 1; else cout << 0; } cout << endl; //*/ int br = 22 - (t%23); int th = 1<<(br+1); vector<int> p1, p0; vector<int> q1, q0; rep(i,N){ if(v[i]>=th) continue; if(w[i]){ if((v[i]>>br)&1) p1.push_back(i); else p0.push_back(i); }else{ if((v[i]>>br)&1) q1.push_back(i); else q0.push_back(i); } if(p1.size()>1 && p0.size()>1 && q1.size()>1 && q0.size()>1) break; } if((score>>br)&1){ if(p1.size()>1 && q0.size()>1){ random_shuffle(ALLOF(p1)); random_shuffle(ALLOF(q0)); int t_score = score; t_score ^= v[p1[0]]; t_score ^= v[p1[1]]; t_score ^= v[q0[0]]; t_score ^= v[q0[1]]; if(score <= t_score){ w[p1[0]] = 0; w[p1[1]] = 0; w[q0[0]] = 1; w[q0[1]] = 1; score ^= v[p1[0]]; score ^= v[p1[1]]; score ^= v[q0[0]]; score ^= v[q0[1]]; } } else if(p0.size()>1 && q1.size()>1){ int t_score = score; t_score ^= v[p0[0]]; t_score ^= v[p0[1]]; t_score ^= v[q1[0]]; t_score ^= v[q1[1]]; if(score <= t_score){ w[p0[0]] = 0; w[p0[1]] = 0; w[q1[0]] = 1; w[q1[1]] = 1; score ^= v[p0[0]]; score ^= v[p0[1]]; score ^= v[q1[0]]; score ^= v[q1[1]]; } } }else{ if(p1.size()>0 && q0.size()>0){ w[p1[0]] = 0; w[q0[0]] = 1; score ^= v[p1[0]]; score ^= v[q0[0]]; } else if(p0.size()>0 && q1.size()>0){ w[p0[0]] = 0; w[q1[0]] = 1; score ^= v[p0[0]]; score ^= v[q1[0]]; } } t++; } cerr << score << endl; for(int i=22; i>=0; i--){ if((score>>i)&1) cerr << 1; else cerr << 0; } cerr << endl; vector<int> ret; rep(i,w.size()){ if(w[i]) ret.push_back(v[i]); } return ret; } int main(){ int N, M; cin >> N >> M; vector<int> v; rep(i,N){ #ifdef LOCAL v.push_back(1+i); #else int a; cin >> a; v.push_back(a); #endif } random_shuffle(ALLOF(v)); timer.start(); vector<int> ret = solve(v, N, M); #ifndef LOCAL rep(i,ret.size()){ if(i>0) cout << " "; cout << ret[i]; } cout << endl; #endif return 0; }