結果

問題 No.5001 排他的論理和でランニング
ユーザー masakt
提出日時 2018-03-17 00:11:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,093 bytes
コンパイル時間 1,581 ms
実行使用メモリ 7,736 KB
スコア 45,821,165
最終ジャッジ日時 2020-03-12 19:44:52
ジャッジサーバーID
(参考情報)
judge10 /
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define INLINE inline __attribute__ ((always_inline))

using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using mt = tuple<ll, ll, ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vmt = vector<mt>;

constexpr double TIME_OUT = 1.2;
constexpr double CYCLES_PER_SEC = 2.8 * 1e9;

INLINE int64_t getCycle() {
    uint32_t low, high;
    __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
    return ((int64_t)low) | ((int64_t)high << 32);
}

INLINE static double getTime() { return getCycle() / CYCLES_PER_SEC; }

INLINE static uint32_t xor128(void) {
    static uint32_t x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    uint32_t t = x ^ (x << 11); x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

INLINE static double getRand() { return (double) xor128() / (1LL << 32); }

int main(int argc, char* argv[], char* envp[]) {
    ll n, m;
    scanf("%lld %lld", &n, &m);
    vll a(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    
    int bestScore = 0;
    set<int> bestState;
    int iter = 0;
    double startTime = getTime();
    while (TIME_OUT > getTime() - startTime) {
        iter++;
        int score = 0;
        set<int> used;
        int remain = m;
        while (0 < remain) {
            int idx;
            while (true) {
                idx = xor128() % n;
                if (0 == used.count(idx)) {
                    used.insert(idx);
                    break;
                }
            }
            score ^= a[idx];
            remain--;
        }
        if (bestScore < score) {
            bestScore = score;
            bestState = used;
        }
    }
    
    vll ans(all(bestState));
    for (int i = 0; i < m; i++) {
        printf("%lld%c", a[ans[i]], (i + 1 == n ? '\n' : ' '));
    }
    
    debug("time:%f iter:%d score:%d\n", getTime() - startTime, iter, bestScore);
    
    return 0;
}
0