結果

問題 No.937 Ultra Sword
ユーザー square1001square1001
提出日時 2020-01-22 21:21:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,476 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 5,384 KB
最終ジャッジ日時 2023-09-23 01:25:37
合計ジャッジ時間 10,489 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 39 ms
4,872 KB
testcase_10 RE -
testcase_11 AC 14 ms
4,376 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 16 ms
4,568 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 21 ms
4,804 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 AC 18 ms
4,640 KB
testcase_45 RE -
testcase_46 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int mx = *max_element(A.begin(), A.end());
	int bits = 0;
	while ((1 << bits) <= mx) ++bits;
	vector<int> cnt(1 << bits);
	for (int i = 0; i < N; ++i) {
		++cnt[A[i]];
	}
	vector<long long> decr(1 << bits);
	for (int i = 1; i < 1 << bits; ++i) {
		for (int j = i; j < 1 << bits; j += i) {
			decr[i] += cnt[j] * j / i * (i - 1);
		}
	}
	long long asum = 0;
	for (int i = 0; i < N; ++i) {
		asum += A[i];
	}
	for (int i = 0; i < N; ++i) {
		sort(A.begin(), A.end(), greater<int>());
		if (A[i] == 0) break;
		for (int j = 0; j < N; ++j) {
			if (j != i && A[j] > (A[j] ^ A[i])) {
				A[j] ^= A[i];
			}
		}
	}
	while (!A.empty() && A.back() == 0) A.pop_back();
	vector<int> B;
	for (int i : A) {
		for (int j = i; j < 1 << bits; j *= 2) {
			B.push_back(j);
		}
	}
	for (int i = 0; i < B.size(); ++i) {
		sort(B.begin(), B.end(), greater<int>());
		if (B[i] == 0) break;
		for (int j = 0; j < N; ++j) {
			if (j != i && B[j] > (B[j] ^ B[i])) {
				B[j] ^= B[i];
			}
		}
	}
	while (!B.empty() && B.back() == 0) B.pop_back();
	long long maxdec = 0;
	for (int i = 1; i < 1 << B.size(); ++i) {
		int xorsum = 0;
		for (int j = 0; j < B.size(); ++j) {
			if ((i >> j) & 1) xorsum ^= B[j];
		}
		maxdec = max(maxdec, decr[xorsum]);
	}
	cout << asum - maxdec << endl;
	return 0;
}
0