結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define INLINE inline __attribute__ ((always_inline))

constexpr double TIME_OUT = 1.47;
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 n, m;
    scanf("%d %d", &n, &m);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(rall(a));
    
    random_device seed_gen;
    mt19937 engine(seed_gen());
    int score = 0;
    vector<int> state(n);
    iota(all(state), 0);
    int bestScore = 0;
    vector<int> bestState(m);
    double startTime = getTime();
    while (TIME_OUT > getTime() - startTime) {
        score = 0;
        for (int i = 0; i < m; i++) {
            score ^= a[state[i]];
        }
        if (bestScore < score) {
            bestScore = score;
            for (int i = 0; i < m; i++) {
                bestState[i] = state[i];
            }
        }
        shuffle(all(state), engine);
    }
    
    for (int i = 0; i < m; i++) {
        printf("%d%c", a[bestState[i]], (i + 1 == n ? '\n' : ' '));
    }
    
    return 0;
}
0