結果

問題 No.937 Ultra Sword
ユーザー beetbeet
提出日時 2019-11-29 22:13:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 3,000 ms
コード長 1,047 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 205,080 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 02:31:57
合計ジャッジ時間 4,352 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,812 KB
testcase_01 AC 15 ms
6,940 KB
testcase_02 AC 13 ms
6,944 KB
testcase_03 AC 14 ms
6,944 KB
testcase_04 AC 13 ms
6,940 KB
testcase_05 AC 40 ms
6,944 KB
testcase_06 AC 36 ms
6,940 KB
testcase_07 AC 38 ms
6,940 KB
testcase_08 AC 26 ms
6,940 KB
testcase_09 AC 23 ms
6,940 KB
testcase_10 AC 43 ms
6,944 KB
testcase_11 AC 20 ms
6,948 KB
testcase_12 AC 37 ms
6,944 KB
testcase_13 AC 37 ms
6,940 KB
testcase_14 AC 40 ms
6,944 KB
testcase_15 AC 32 ms
6,940 KB
testcase_16 AC 16 ms
6,940 KB
testcase_17 AC 17 ms
6,944 KB
testcase_18 AC 36 ms
6,944 KB
testcase_19 AC 27 ms
6,944 KB
testcase_20 AC 27 ms
6,944 KB
testcase_21 AC 43 ms
6,944 KB
testcase_22 AC 14 ms
6,940 KB
testcase_23 AC 16 ms
6,940 KB
testcase_24 AC 39 ms
6,944 KB
testcase_25 AC 37 ms
6,940 KB
testcase_26 AC 30 ms
6,940 KB
testcase_27 AC 31 ms
6,940 KB
testcase_28 AC 33 ms
6,940 KB
testcase_29 AC 13 ms
6,944 KB
testcase_30 AC 28 ms
6,940 KB
testcase_31 AC 40 ms
6,940 KB
testcase_32 AC 28 ms
6,944 KB
testcase_33 AC 40 ms
6,940 KB
testcase_34 AC 17 ms
6,940 KB
testcase_35 AC 15 ms
6,940 KB
testcase_36 AC 36 ms
6,940 KB
testcase_37 AC 15 ms
6,940 KB
testcase_38 AC 29 ms
6,940 KB
testcase_39 AC 14 ms
6,944 KB
testcase_40 AC 33 ms
6,944 KB
testcase_41 AC 21 ms
6,940 KB
testcase_42 AC 31 ms
6,944 KB
testcase_43 AC 27 ms
6,940 KB
testcase_44 AC 18 ms
6,940 KB
testcase_45 AC 22 ms
6,940 KB
testcase_46 AC 23 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0