#include 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 >; using vmt = vector; constexpr double TIME_OUT = 1.0; constexpr double CYCLES_PER_SEC = 2.6 * 1e9; constexpr int BEAM_WIDTH = 5; 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 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 = xor128() % n; if (0 < get<1>(state).count(idx)) { for (int i = 0; i < n; i++) { (idx += 1) %= n; if (0 == get<1>(state).count(idx)) { break; } } } get<1>(state).insert(idx); 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 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; }