結果

問題 No.5001 排他的論理和でランニング
ユーザー treeonetreeone
提出日時 2018-03-17 02:48:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,485 ms / 1,500 ms
コード長 3,673 bytes
コンパイル時間 1,680 ms
実行使用メモリ 15,344 KB
スコア 51,361,906
最終ジャッジ日時 2020-03-12 19:55:55
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,478 ms
13,864 KB
testcase_01 AC 1,470 ms
5,380 KB
testcase_02 AC 1,477 ms
6,200 KB
testcase_03 AC 1,476 ms
8,832 KB
testcase_04 AC 1,482 ms
14,928 KB
testcase_05 AC 1,474 ms
7,168 KB
testcase_06 AC 1,478 ms
9,412 KB
testcase_07 AC 1,472 ms
10,592 KB
testcase_08 AC 1,484 ms
14,056 KB
testcase_09 AC 1,473 ms
5,380 KB
testcase_10 AC 1,478 ms
6,804 KB
testcase_11 AC 1,479 ms
8,364 KB
testcase_12 AC 1,474 ms
6,480 KB
testcase_13 AC 1,479 ms
14,268 KB
testcase_14 AC 1,480 ms
9,932 KB
testcase_15 AC 1,478 ms
7,020 KB
testcase_16 AC 1,475 ms
5,376 KB
testcase_17 AC 1,473 ms
6,244 KB
testcase_18 AC 1,477 ms
9,848 KB
testcase_19 AC 1,477 ms
7,596 KB
testcase_20 AC 1,479 ms
0 KB
testcase_21 AC 1,476 ms
6,396 KB
testcase_22 AC 1,474 ms
5,376 KB
testcase_23 AC 1,477 ms
5,380 KB
testcase_24 AC 1,474 ms
7,724 KB
testcase_25 AC 1,474 ms
12,308 KB
testcase_26 AC 1,475 ms
11,208 KB
testcase_27 AC 1,475 ms
8,376 KB
testcase_28 AC 1,478 ms
10,464 KB
testcase_29 AC 1,476 ms
11,792 KB
testcase_30 AC 1,470 ms
5,380 KB
testcase_31 AC 1,480 ms
10,300 KB
testcase_32 AC 1,479 ms
6,508 KB
testcase_33 AC 1,484 ms
14,460 KB
testcase_34 AC 1,480 ms
15,344 KB
testcase_35 AC 1,477 ms
10,340 KB
testcase_36 AC 1,478 ms
13,636 KB
testcase_37 AC 1,485 ms
11,192 KB
testcase_38 AC 1,475 ms
6,304 KB
testcase_39 AC 1,474 ms
7,356 KB
testcase_40 AC 1,476 ms
8,424 KB
testcase_41 AC 1,480 ms
5,380 KB
testcase_42 AC 1,477 ms
8,264 KB
testcase_43 AC 1,478 ms
8,796 KB
testcase_44 AC 1,476 ms
12,304 KB
testcase_45 AC 1,478 ms
13,264 KB
testcase_46 AC 1,477 ms
12,660 KB
testcase_47 AC 1,475 ms
7,648 KB
testcase_48 AC 1,472 ms
6,396 KB
testcase_49 AC 1,485 ms
12,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;
unsigned w;
unsigned xor128() {
  static unsigned x = 123456789, y = 362436069, z = 521288629/*, w = 88675123*/;
  unsigned t = (x ^ (x << 11));
  x = y; y = z; z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
class Timer {
private:
  clock_t start;
public:
  Timer() {
    start = clock();
  }
  double sec() {
    clock_t end = clock();
    return (double) (end - start) / CLOCKS_PER_SEC;
  }
};
const double TimeLimit = 1.450;
Timer timer;

void display(int now){
    repb(i, 19, 0){
        if(now & (1LL << i)) cerr << "1";
        else cerr << "0";
    }
    cerr << endl;
    return;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    clock_t start, end;
	start = clock();
	random_device rnd;
	mt19937 mt((int)time(0));
    w = mt();
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> d[20], e[20];
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(all(a));
    rep(i, 0, n){
        bool f = true;
        repb(j, 19, 0){
            if(a[i] & (1LL << j)){
                if(f){
                    d[j].push_back(i);
                    f = false;
                }
                e[j].push_back(i);
            }
        }
    }
    // vector<int> ans;
    set<int> st;
    int now = 0;
    repb(i, 19, 0){
        if(st.size() == m) break;
        int limit = min(m / 15, (int)d[i].size());
        limit = min(limit, m - (int)st.size());
        if(now & (1LL << i)){
            if(limit % 2) limit--;
        }else{
            if(limit % 2 == 0) limit--;
        }
        cerr << i << " " << limit << " " << (now & (1LL << i)) << endl;
        rep(j, 0, limit){
            now ^= a[d[i][j]];
            st.insert(d[i][j]);
        }
    }
    rep(i, 0, 20){
        rep(j, 0, d[i].size()){
            if(st.size() == m) break;
            if(!st.count(d[i][j])){
                now ^= a[d[i][j]];
                // ans.push_back(i);
                st.insert(d[i][j]);
            }
        }
    }
    cerr << st.size() << " " << now << endl;
    display(now);
    int cnt = 0, grow = 0, high = -1;
	while(1){
		double tmp = timer.sec();
		if(tmp > TimeLimit){
            break;
        }
        // if(high == -1){
        //     repb(i, 19, 0){
        //         if(now & (1LL << i)) continue;
        //         high = i; break;
        //     }
        //     if(high == -1) break;
        // }
        int id = xor128() % n;
        // if(!st.count(id)) continue;
        // if(d[high].size() == 0) continue;
        // int id2 = xor128() % (int)(d[high].size());
        // if(st.count(id2)) continue;
        // id2 = d[high][id2];
        int id2 = xor128() % n;
        if(!(st.count(id) ^ st.count(id2))) continue;
        if(st.count(id2)) swap(id, id2); 
        cnt++;
        int tmp2 = now ^ a[id] ^ a[id2];
        if(tmp2 > now){
            now = tmp2;
            st.erase(id);
            st.insert(id2);
            grow++;
        }
		// if((int)(tmp * 1000) % 1000 <= 20){
		// 	cerr << tmp << " " << now << endl;
		// }
    }
    int sum = 0;
    for(auto it = st.begin(); it != st.end(); it++){
        if(it != st.begin()) cout << ' ';
        cout << a[*it];
        sum ^= a[*it];
    }
    cout << endl;
    cerr << now << " " << sum << " " << cnt << " " << grow << endl;
    display(now);
}
0