結果

問題 No.5001 排他的論理和でランニング
ユーザー masaktmasakt
提出日時 2018-03-17 01:28:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,394 bytes
コンパイル時間 2,780 ms
実行使用メモリ 10,808 KB
スコア 0
最終ジャッジ日時 2020-03-12 19:50:06
ジャッジサーバーID
(参考情報)
judge7 /
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

using mt = tuple<int, set<int> >;
using vmt = vector<mt>;

constexpr double TIME_OUT = 1.4;
constexpr double CYCLES_PER_SEC = 2.6 * 1e9;
constexpr int BEAM_WIDTH = 20;

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[]) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    
    mt bestState;
    int iter = 0;
    double startTime = getTime();
    while (TIME_OUT > getTime() - startTime) {
        iter++;
        int remain = m;
        vmt states(BEAM_WIDTH);
        mt state;
        while (0 < remain) {
            for (int b = 0; b < BEAM_WIDTH; b++) {
                state = states[b];
                int idx;
                while (true) {
                    idx = xor128() % n;
                    if (0 == get<1>(state).count(idx)) {
                        get<1>(state).insert(idx);
                        break;
                    }
                }
                get<0>(state) = get<0>(state) ^ a[idx];
                states[b] = state;
            }
            sort(rall(states));
            states.resize(BEAM_WIDTH);
            remain--;
        }
        state = states.front();
        if (get<0>(bestState) < get<0>(state)) {
            get<0>(bestState) = get<0>(state);
            get<1>(bestState) = get<1>(state);
        }
    }
    
    vector<int> ans(all(get<1>(bestState)));
    for (int i = 0; i < m; i++) {
        printf("%d%c", a[ans[i]], (i + 1 == n ? '\n' : ' '));
    }
    
    debug("time:%f iter:%d score:%d\n", getTime() - startTime, iter, get<0>(bestState));
    
    return 0;
}
0