結果

問題 No.937 Ultra Sword
ユーザー leaf_1415leaf_1415
提出日時 2019-11-29 23:30:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,702 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 60,372 KB
実行使用メモリ 20,804 KB
最終ジャッジ日時 2024-05-01 02:54:25
合計ジャッジ時間 13,232 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
6,816 KB
testcase_01 AC 112 ms
6,940 KB
testcase_02 AC 111 ms
6,940 KB
testcase_03 AC 85 ms
6,940 KB
testcase_04 AC 77 ms
6,940 KB
testcase_05 AC 271 ms
20,120 KB
testcase_06 AC 389 ms
18,544 KB
testcase_07 AC 415 ms
20,680 KB
testcase_08 AC 244 ms
12,496 KB
testcase_09 AC 208 ms
9,772 KB
testcase_10 AC 449 ms
20,740 KB
testcase_11 AC 131 ms
10,060 KB
testcase_12 AC 379 ms
20,184 KB
testcase_13 AC 356 ms
17,748 KB
testcase_14 AC 399 ms
20,308 KB
testcase_15 AC 311 ms
18,248 KB
testcase_16 AC 82 ms
6,944 KB
testcase_17 AC 105 ms
6,940 KB
testcase_18 AC 345 ms
17,832 KB
testcase_19 AC 225 ms
14,384 KB
testcase_20 AC 210 ms
12,072 KB
testcase_21 AC 260 ms
20,648 KB
testcase_22 WA -
testcase_23 AC 113 ms
6,940 KB
testcase_24 AC 277 ms
20,236 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[2000005];

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 < 20; j++){
			b[j*n+i] = a[i] << j;
		}
	}
	GaussianElimination(b, n*20);
	
	//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 = 39; 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