結果

問題 No.937 Ultra Sword
ユーザー leaf_1415leaf_1415
提出日時 2019-11-29 23:34:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,702 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 61,488 KB
実行使用メモリ 36,284 KB
最終ジャッジ日時 2024-05-01 02:56:38
合計ジャッジ時間 26,470 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
6,816 KB
testcase_01 AC 178 ms
6,944 KB
testcase_02 AC 176 ms
6,940 KB
testcase_03 AC 106 ms
6,940 KB
testcase_04 AC 100 ms
6,940 KB
testcase_05 AC 494 ms
35,816 KB
testcase_06 AC 915 ms
31,852 KB
testcase_07 AC 1,009 ms
34,144 KB
testcase_08 AC 519 ms
17,992 KB
testcase_09 AC 429 ms
15,436 KB
testcase_10 AC 1,104 ms
36,284 KB
testcase_11 AC 236 ms
10,696 KB
testcase_12 AC 886 ms
34,008 KB
testcase_13 AC 880 ms
31,700 KB
testcase_14 AC 982 ms
35,948 KB
testcase_15 AC 734 ms
27,376 KB
testcase_16 AC 95 ms
6,944 KB
testcase_17 AC 146 ms
7,632 KB
testcase_18 AC 802 ms
31,816 KB
testcase_19 AC 490 ms
21,448 KB
testcase_20 AC 434 ms
17,872 KB
testcase_21 AC 539 ms
36,224 KB
testcase_22 WA -
testcase_23 AC 176 ms
6,940 KB
testcase_24 AC 517 ms
35,916 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <bitset>
#define llint long long

using namespace std;

llint n;
llint cnt[100005];
bool prime[100005];
vector<llint> pvec;
llint a[100005], b[4000005];

void GaussianElimination(llint a[], int n)
{
	llint r = 0;
	for(int i = 59; i >= 0 && r < n; i--){ //上位ビットから見ていく
		if((a[r]&(1LL<<i)) == 0){
			int p = -1;
			for(int j = r+1; j < n; j++){
				if(a[j] & (1LL<<i)){
					p = j;
					break;
				}
			}
			if(p == -1) goto end;
			swap(a[r], a[p]);
		}
		for(int j = 0; j < n; j++){
			if(j == r) continue;
			if(a[j]&(1LL<<i)) a[j] ^= a[r];
		}
		r++;
		end:;
	}
}

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]] += a[i];
	}
	
	for(int i = 2; i < 100005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 100005; j+=i) prime[j] = true;
	}
	
	for(int i = 2; i < 100005; i++){
		if(prime[i]) continue;
		for(int j = 100004/i; j >= 1; j--){
			cnt[j] += cnt[j*i];
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 40; j++){
			b[j*n+i] = a[i] << j;
		}
	}
	GaussianElimination(b, n*40);
	
	//for(int i = 0; i < 50; i++) cout << bitset<30>(b[i]) << endl;
	
	llint sum = 0;
	for(int i = 0; i < n; i++) sum += a[i];
	
	llint ans = sum+1;
	for(int i = 1; i <= 100000; i++){
		llint tmp = 0, pre = -1;
		for(int j = 59; j >= 0; j--){
			bool found = false;
			for(int k = pre+1; k < 50; k++){
				if(b[k]&(1LL<<k)){
					found = true;
					tmp ^= b[k];
					pre = k;
					break;
				}
			}
			if(tmp&(1LL<<j) != (i&(1LL<<j)) && !found) goto end;
		}
		//cout << i << " " << sum << " " << cnt[i] << endl;
		ans = min(ans, sum-cnt[i]+cnt[i]/i);
		end:;
	}
	cout << ans << endl;
	
	return 0;
}
0