結果
| 問題 | No.937 Ultra Sword | 
| コンテスト | |
| ユーザー |  beet | 
| 提出日時 | 2019-11-29 22:13:55 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 62 ms / 3,000 ms | 
| コード長 | 1,047 bytes | 
| コンパイル時間 | 2,213 ms | 
| コンパイル使用メモリ | 196,468 KB | 
| 最終ジャッジ日時 | 2025-01-08 06:02:54 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 47 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
Int calc(Int x,Int y){
  if(x<y) swap(x,y);
  while(y){
    Int p=__builtin_clz(x);
    Int q=__builtin_clz(y);
    x^=y<<(q-p);
    if(x<y) swap(x,y);
  }
  return x;
}
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];
  Int g=as[0];
  for(Int i=0;i<n;i++) g=calc(g,as[i]);
  //cout<<g<<endl;
  Int sum=0;
  for(Int i=0;i<n;i++) sum+=as[i];
  const Int LOG = 18;
  const Int MAX = 1<<LOG;
  vector<Int> dp(MAX,0);
  for(Int i=0;i<n;i++) dp[as[i]]+=as[i];
  for(Int i=1;i<MAX;i++)
    for(Int j=i+i;j<MAX;j+=i)
      dp[i]+=dp[j];
  Int ans=sum;
  for(Int bit=1;bit<MAX;bit++){
    Int res=0;
    for(Int i=0;i<LOG;i++)
      if((bit>>i)&1) res^=g<<i;
    if(res>=MAX) continue;
    chmin(ans,sum-(dp[res]-dp[res]/res));
  }
  cout<<ans<<endl;
  return 0;
}
            
            
            
        