結果

問題 No.5001 排他的論理和でランニング
ユーザー masakt
提出日時 2018-03-17 02:52:03
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,514 bytes
コンパイル時間 1,906 ms
スコア 0
最終ジャッジ日時 2020-03-12 19:56:35
ジャッジサーバーID
(参考情報)
judge6 /
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 50
権限があれば一括ダウンロードができます

ソースコード

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))

constexpr double TIME_OUT = 1.475;
constexpr double CYCLES_PER_SEC = 2.6 * 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; }

int main(int argc, char* argv[], char* envp[]) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    
    random_device seed_gen;
    mt19937 engine(seed_gen());
    int bestScore = 0;
    vector<int> bestState;
    int iter = 0;
    double startTime = getTime();
    while (TIME_OUT > getTime() - startTime) {
        iter++;
        int score = 0;
        vector<int> state(n);
        iota(all(state), 0);
        shuffle(all(state), engine);
        state.resize(m);
        for (int i = 0; i < m; i++) {
            int idx = state[i];
            score ^= a[idx];
        }
        if (bestScore < score) {
            bestScore = score;
            bestState = state;
        }
    }
    
    for (int i = 0; i < m; i++) {
        printf("%d%c", a[bestState[i]], (i + 1 == n ? '\n' : ' '));
    }
    
    debug("time:%f iter:%d score:%d\n", getTime() - startTime, iter, bestScore);
    
    return 0;
}
0