結果

問題 No.5001 排他的論理和でランニング
ユーザー trineutron
提出日時 2022-05-15 15:54:01
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,037 ms / 1,500 ms
コード長 844 bytes
コンパイル時間 2,201 ms
実行使用メモリ 3,636 KB
スコア 52,428,672
最終ジャッジ日時 2022-05-15 15:55:00
合計ジャッジ時間 58,102 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

uint64_t rng() {
	static uint64_t x = 1;
	x ^= x << 9;
	return x ^= x >> 7;
}

int main() {
	clock_t start = clock();
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<bool> used(n), best_used(n);
	int score = 0, best = 0;
	for (int i = 0; i < m; i++) {
		used[i] = true;
		score ^= a[i];
	}
	best_used = used;
	best = score;
	uniform_int_distribution<> dist(0, n - 1);
	while (clock() - start < CLOCKS_PER_SEC) {
		int x = rng() % n, y = rng() % n;
		if (used[x] == used[y]) continue;
		swap(used[x], used[y]);
		score ^= a[x] ^ a[y];
		if (score > best) {
			best_used = used;
			best = score;
		}
	}
	int count = m;
	for (int i = 0; i < n; i++) {
		if (best_used[i]) {
			cout << a[i];
			m--;
			if (m) cout << ' ';
		}
	}
	cout << endl;
}
0