結果

問題 No.937 Ultra Sword
ユーザー kotatsugamekotatsugame
提出日時 2019-11-29 22:51:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 3,000 ms
コード長 891 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 68,340 KB
実行使用メモリ 18,056 KB
最終ジャッジ日時 2024-05-01 02:45:23
合計ジャッジ時間 6,782 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,812 KB
testcase_01 AC 9 ms
6,944 KB
testcase_02 AC 9 ms
6,940 KB
testcase_03 AC 8 ms
6,940 KB
testcase_04 AC 7 ms
6,944 KB
testcase_05 AC 96 ms
17,412 KB
testcase_06 AC 205 ms
15,760 KB
testcase_07 AC 227 ms
17,372 KB
testcase_08 AC 105 ms
10,452 KB
testcase_09 AC 73 ms
9,332 KB
testcase_10 AC 247 ms
17,180 KB
testcase_11 AC 45 ms
6,940 KB
testcase_12 AC 209 ms
15,952 KB
testcase_13 AC 182 ms
15,672 KB
testcase_14 AC 219 ms
17,288 KB
testcase_15 AC 175 ms
14,416 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 24 ms
6,944 KB
testcase_18 AC 196 ms
15,476 KB
testcase_19 AC 113 ms
11,572 KB
testcase_20 AC 97 ms
9,880 KB
testcase_21 AC 149 ms
18,056 KB
testcase_22 AC 9 ms
6,944 KB
testcase_23 AC 8 ms
6,944 KB
testcase_24 AC 103 ms
17,612 KB
testcase_25 AC 144 ms
16,640 KB
testcase_26 AC 142 ms
14,660 KB
testcase_27 AC 130 ms
14,844 KB
testcase_28 AC 179 ms
16,292 KB
testcase_29 AC 11 ms
6,940 KB
testcase_30 AC 129 ms
12,468 KB
testcase_31 AC 181 ms
17,516 KB
testcase_32 AC 96 ms
12,888 KB
testcase_33 AC 158 ms
17,944 KB
testcase_34 AC 36 ms
7,848 KB
testcase_35 AC 18 ms
6,944 KB
testcase_36 AC 155 ms
16,908 KB
testcase_37 AC 20 ms
7,364 KB
testcase_38 AC 134 ms
13,476 KB
testcase_39 AC 13 ms
6,944 KB
testcase_40 AC 130 ms
16,080 KB
testcase_41 AC 52 ms
9,744 KB
testcase_42 AC 101 ms
12,840 KB
testcase_43 AC 102 ms
12,244 KB
testcase_44 AC 48 ms
8,132 KB
testcase_45 AC 65 ms
10,284 KB
testcase_46 AC 86 ms
9,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N,A[1<<17];
long S[1<<17];
long sum=0,ans=0;
long B[1700000];
bool dp[1<<17];
main()
{
	cin>>N;
	int sz=0;
	for(int i=0;i<N;i++)
	{
		long a;cin>>a;A[a]++;
		sum+=a;
		for(int j=0;j<17;j++)
		{
			B[i*17+j]=a<<j;
		}
	}
	for(int i=100000;i>1;i--)
	{
		for(int j=i;j<=100000;j+=i)
		{
			S[i]+=A[j]*(long)(j/i*(i-1));
		}
	}
	int idx=0;
	for(int i=33;i>=0;i--)
	{
		int id=-1;
		for(int j=idx;j<17*N;j++)
		{
			if(B[j]>>i&1)
			{
				id=j;
				break;
			}
		}
		if(id<0)continue;
		if(id!=idx)
		{
			swap(B[id],B[idx]);
		}
		for(int j=0;j<17*N;j++)
		{
			if(idx!=j&&B[j]>>i&1)B[j]^=B[idx];
		}
		idx++;
	}
	dp[0]=true;
	for(int i=0;i<17*N;i++)
	{
		if(B[i]&&!(B[i]>>17))
		{
			for(int k=0;k<1<<17;k++)
			{
				if(dp[k])dp[k^B[i]]=true;
			}
		}
	}
	for(int i=0;i<1<<17;i++)if(dp[i])ans=max(ans,S[i]);
	cout<<sum-ans<<endl;
}
0