結果

問題 No.937 Ultra Sword
ユーザー 👑 kmjpkmjp
提出日時 2019-11-30 02:08:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 3,000 ms
コード長 1,333 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 166,032 KB
実行使用メモリ 4,948 KB
最終ジャッジ日時 2023-08-13 09:28:02
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,380 KB
testcase_01 AC 14 ms
4,388 KB
testcase_02 AC 14 ms
4,380 KB
testcase_03 AC 14 ms
4,380 KB
testcase_04 AC 14 ms
4,384 KB
testcase_05 AC 23 ms
4,504 KB
testcase_06 AC 32 ms
4,796 KB
testcase_07 AC 34 ms
4,836 KB
testcase_08 AC 23 ms
4,656 KB
testcase_09 AC 21 ms
4,608 KB
testcase_10 AC 36 ms
4,876 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 29 ms
4,556 KB
testcase_13 AC 29 ms
4,496 KB
testcase_14 AC 32 ms
4,544 KB
testcase_15 AC 27 ms
4,432 KB
testcase_16 AC 15 ms
4,380 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 28 ms
4,464 KB
testcase_19 AC 22 ms
4,384 KB
testcase_20 AC 21 ms
4,388 KB
testcase_21 AC 34 ms
4,908 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 15 ms
4,380 KB
testcase_24 AC 27 ms
4,564 KB
testcase_25 AC 26 ms
4,856 KB
testcase_26 AC 25 ms
4,780 KB
testcase_27 AC 24 ms
4,780 KB
testcase_28 AC 27 ms
4,816 KB
testcase_29 AC 14 ms
4,772 KB
testcase_30 AC 23 ms
4,892 KB
testcase_31 AC 27 ms
4,940 KB
testcase_32 AC 22 ms
4,720 KB
testcase_33 AC 27 ms
4,948 KB
testcase_34 AC 16 ms
4,548 KB
testcase_35 AC 15 ms
4,596 KB
testcase_36 AC 25 ms
4,844 KB
testcase_37 AC 15 ms
4,528 KB
testcase_38 AC 23 ms
4,868 KB
testcase_39 AC 15 ms
4,576 KB
testcase_40 AC 24 ms
4,864 KB
testcase_41 AC 18 ms
4,624 KB
testcase_42 AC 22 ms
4,736 KB
testcase_43 AC 22 ms
4,784 KB
testcase_44 AC 17 ms
4,560 KB
testcase_45 AC 19 ms
4,616 KB
testcase_46 AC 21 ms
4,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int C[101010];

ll ret[101010];

int GCD(int x,int y) {
	if(x<y) swap(x,y);
	if(y==0) return x;
	int z=y;
	while(__builtin_clz(x)!=__builtin_clz(z)) z<<=1;
	
	return GCD(y,x^z);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll sum=0;
	int g=0;
	FOR(i,N) {
		cin>>A[i];
		g=GCD(g,A[i]);
		C[A[i]]++;
		sum+=A[i];
	}
	ll mi=1LL<<60;
	for(i=1;i<=100000;i++) {
		ret[i]=sum;
		for(j=i;j<=100000;j+=i) {
			ret[i]-=1LL*C[j]*j;
			ret[i]+=1LL*C[j]*(j/i);
		}
		if(i%g==0) mi=min(mi,ret[i]);
	}
	for(int m=1;m<1<<17;m++) {
		ll t=0;
		FOR(i,17) if(m&(1<<i)) t^=(ll)g<<i;
		if(t<=100000) mi=min(mi,ret[t]);
	}
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0