結果

問題 No.937 Ultra Sword
ユーザー beetbeet
提出日時 2019-11-29 22:13:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 3,000 ms
コード長 1,047 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 202,080 KB
実行使用メモリ 6,080 KB
最終ジャッジ日時 2023-08-13 08:55:10
合計ジャッジ時間 5,060 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
5,200 KB
testcase_01 AC 19 ms
5,092 KB
testcase_02 AC 16 ms
5,088 KB
testcase_03 AC 16 ms
5,060 KB
testcase_04 AC 16 ms
5,196 KB
testcase_05 AC 46 ms
5,796 KB
testcase_06 AC 40 ms
5,588 KB
testcase_07 AC 43 ms
5,584 KB
testcase_08 AC 29 ms
5,388 KB
testcase_09 AC 27 ms
5,084 KB
testcase_10 AC 46 ms
6,080 KB
testcase_11 AC 22 ms
5,096 KB
testcase_12 AC 42 ms
5,728 KB
testcase_13 AC 40 ms
5,532 KB
testcase_14 AC 43 ms
5,912 KB
testcase_15 AC 37 ms
5,588 KB
testcase_16 AC 18 ms
5,144 KB
testcase_17 AC 20 ms
5,104 KB
testcase_18 AC 39 ms
5,676 KB
testcase_19 AC 30 ms
5,352 KB
testcase_20 AC 29 ms
5,332 KB
testcase_21 AC 46 ms
5,796 KB
testcase_22 AC 16 ms
5,148 KB
testcase_23 AC 18 ms
5,124 KB
testcase_24 AC 44 ms
5,992 KB
testcase_25 AC 41 ms
5,580 KB
testcase_26 AC 36 ms
5,644 KB
testcase_27 AC 36 ms
5,588 KB
testcase_28 AC 39 ms
5,724 KB
testcase_29 AC 16 ms
5,092 KB
testcase_30 AC 32 ms
5,272 KB
testcase_31 AC 43 ms
5,884 KB
testcase_32 AC 31 ms
5,364 KB
testcase_33 AC 44 ms
6,076 KB
testcase_34 AC 20 ms
5,348 KB
testcase_35 AC 17 ms
5,276 KB
testcase_36 AC 40 ms
5,672 KB
testcase_37 AC 18 ms
5,052 KB
testcase_38 AC 34 ms
5,744 KB
testcase_39 AC 17 ms
5,100 KB
testcase_40 AC 37 ms
5,628 KB
testcase_41 AC 24 ms
5,460 KB
testcase_42 AC 33 ms
5,352 KB
testcase_43 AC 31 ms
5,320 KB
testcase_44 AC 21 ms
5,196 KB
testcase_45 AC 26 ms
5,272 KB
testcase_46 AC 26 ms
5,544 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