結果
| 問題 | No.5001 排他的論理和でランニング |
| ユーザー |
masakt
|
| 提出日時 | 2018-03-17 01:43:06 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,400 bytes |
| コンパイル時間 | 2,436 ms |
| 実行使用メモリ | 10,808 KB |
| スコア | 0 |
| 最終ジャッジ日時 | 2020-03-12 19:50:54 |
|
ジャッジサーバーID (参考情報) |
judge8 / |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 49 |
ソースコード
#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.0;
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;
}
masakt