結果
問題 | No.5001 排他的論理和でランニング |
ユーザー | どらら |
提出日時 | 2018-03-17 14:26:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,255 ms / 1,500 ms |
コード長 | 3,777 bytes |
コンパイル時間 | 1,508 ms |
実行使用メモリ | 7,484 KB |
スコア | 52,428,598 |
最終ジャッジ日時 | 2020-03-12 20:08:17 |
ジャッジサーバーID (参考情報) |
judge10 / |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,251 ms
5,380 KB |
testcase_01 | AC | 1,210 ms
5,380 KB |
testcase_02 | AC | 1,215 ms
5,380 KB |
testcase_03 | AC | 1,227 ms
5,376 KB |
testcase_04 | AC | 1,255 ms
5,384 KB |
testcase_05 | AC | 1,221 ms
5,376 KB |
testcase_06 | AC | 1,233 ms
6,148 KB |
testcase_07 | AC | 1,237 ms
5,380 KB |
testcase_08 | AC | 1,247 ms
5,376 KB |
testcase_09 | AC | 1,202 ms
5,380 KB |
testcase_10 | AC | 1,217 ms
5,376 KB |
testcase_11 | AC | 1,223 ms
5,380 KB |
testcase_12 | AC | 1,217 ms
5,380 KB |
testcase_13 | AC | 1,249 ms
5,380 KB |
testcase_14 | AC | 1,233 ms
5,380 KB |
testcase_15 | AC | 1,219 ms
5,376 KB |
testcase_16 | AC | 1,210 ms
5,376 KB |
testcase_17 | AC | 1,214 ms
5,376 KB |
testcase_18 | AC | 1,229 ms
7,424 KB |
testcase_19 | AC | 1,222 ms
5,376 KB |
testcase_20 | AC | 1,217 ms
5,376 KB |
testcase_21 | AC | 1,215 ms
5,376 KB |
testcase_22 | AC | 1,208 ms
5,376 KB |
testcase_23 | AC | 1,205 ms
5,380 KB |
testcase_24 | AC | 1,221 ms
5,376 KB |
testcase_25 | AC | 1,243 ms
5,380 KB |
testcase_26 | AC | 1,237 ms
7,484 KB |
testcase_27 | AC | 1,225 ms
5,380 KB |
testcase_28 | AC | 1,235 ms
5,380 KB |
testcase_29 | AC | 1,242 ms
5,376 KB |
testcase_30 | AC | 1,208 ms
5,376 KB |
testcase_31 | AC | 1,235 ms
5,380 KB |
testcase_32 | AC | 1,216 ms
5,384 KB |
testcase_33 | AC | 1,251 ms
5,384 KB |
testcase_34 | AC | 1,254 ms
7,420 KB |
testcase_35 | AC | 1,235 ms
5,376 KB |
testcase_36 | AC | 1,250 ms
5,376 KB |
testcase_37 | AC | 1,239 ms
5,376 KB |
testcase_38 | AC | 1,215 ms
7,480 KB |
testcase_39 | AC | 1,220 ms
5,380 KB |
testcase_40 | AC | 1,226 ms
5,376 KB |
testcase_41 | AC | 1,208 ms
5,380 KB |
testcase_42 | AC | 1,224 ms
5,380 KB |
testcase_43 | AC | 1,227 ms
5,380 KB |
testcase_44 | AC | 1,244 ms
5,376 KB |
testcase_45 | AC | 1,247 ms
5,380 KB |
testcase_46 | AC | 1,246 ms
5,380 KB |
testcase_47 | AC | 1,222 ms
5,380 KB |
testcase_48 | AC | 1,217 ms
5,380 KB |
testcase_49 | AC | 1,242 ms
5,380 KB |
ソースコード
#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; } }; vector<int> solve(const vector<int>& v, int N, int M, double tle){ Timer timer; timer.start(); bitset<100005> w; int score = 0; rep(i,M){ w[i] = 1; score ^= v[i]; } int t = 0; while(timer.getSec()<tle){ /* 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)); vector<int> ret1 = solve(v, N, M, 0.6); random_shuffle(ALLOF(v)); vector<int> ret2 = solve(v, N, M, 0.6); int score1 = 0, score2 = 0; rep(i,M){ score1 ^= ret1[i]; score2 ^= ret2[i]; } int score = max(score1, score2); vector<int> ret; if(score == score1){ ret = ret1; } else if(score == score2){ ret = ret2; } #ifndef LOCAL rep(i,ret.size()){ if(i>0) cout << " "; cout << ret[i]; } cout << endl; #endif return 0; }