結果

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

ソースコード

diff #

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

mt19937_64 rng;

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 = dist(rng), y = dist(rng);
		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