結果

問題 No.5001 排他的論理和でランニング
ユーザー trineutron
提出日時 2022-05-15 16:50:14
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,438 ms / 1,500 ms
コード長 818 bytes
コンパイル時間 1,597 ms
実行使用メモリ 6,956 KB
スコア 52,428,750
最終ジャッジ日時 2022-05-15 16:51:35
合計ジャッジ時間 77,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];
	}
	int score = 0, best = 0;
	for (int i = 0; i < m; i++) {
		score ^= a[i];
	}
	vector<int> ans(m);
	copy(a.begin(), a.begin() + m, ans.begin());
	best = score;
	while (clock() - start < 1.4 * CLOCKS_PER_SEC) {
		if (m == 0 or m == n) break;
		for (int i = 0; i < m; i++) {
			int x = i, y = rng() % (n - m) + m;
			score ^= a[x] ^ a[y];
			swap(a[x], a[y]);
			if (score > best) {
				copy(a.begin(), a.begin() + m, ans.begin());
				best = score;
			}
		}
	}
	for (int i = 0; i < m; i++) {
		cout << ans[i];
		if (i < m - 1) cout << ' ';
	}
	cout << endl;
}
0