結果

問題 No.937 Ultra Sword
ユーザー lumc_lumc_
提出日時 2019-11-30 00:10:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 3,000 ms
コード長 1,436 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 103,964 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 09:25:00
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
4,380 KB
testcase_01 AC 48 ms
4,380 KB
testcase_02 AC 37 ms
4,384 KB
testcase_03 AC 38 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 12 ms
4,384 KB
testcase_06 AC 70 ms
4,380 KB
testcase_07 AC 73 ms
4,384 KB
testcase_08 AC 59 ms
4,384 KB
testcase_09 AC 56 ms
4,384 KB
testcase_10 AC 75 ms
4,384 KB
testcase_11 AC 51 ms
4,384 KB
testcase_12 AC 66 ms
4,380 KB
testcase_13 AC 66 ms
4,384 KB
testcase_14 AC 69 ms
4,380 KB
testcase_15 AC 64 ms
4,380 KB
testcase_16 AC 48 ms
4,380 KB
testcase_17 AC 49 ms
4,384 KB
testcase_18 AC 65 ms
4,380 KB
testcase_19 AC 57 ms
4,380 KB
testcase_20 AC 56 ms
4,384 KB
testcase_21 AC 72 ms
4,380 KB
testcase_22 AC 38 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 54 ms
4,380 KB
testcase_25 AC 48 ms
4,380 KB
testcase_26 AC 48 ms
4,380 KB
testcase_27 AC 46 ms
4,384 KB
testcase_28 AC 50 ms
4,380 KB
testcase_29 AC 35 ms
4,380 KB
testcase_30 AC 46 ms
4,384 KB
testcase_31 AC 50 ms
4,380 KB
testcase_32 AC 43 ms
4,380 KB
testcase_33 AC 49 ms
4,380 KB
testcase_34 AC 37 ms
4,384 KB
testcase_35 AC 36 ms
4,380 KB
testcase_36 AC 48 ms
4,384 KB
testcase_37 AC 36 ms
4,380 KB
testcase_38 AC 45 ms
4,380 KB
testcase_39 AC 35 ms
4,384 KB
testcase_40 AC 46 ms
4,380 KB
testcase_41 AC 38 ms
4,380 KB
testcase_42 AC 44 ms
4,380 KB
testcase_43 AC 44 ms
4,380 KB
testcase_44 AC 38 ms
4,384 KB
testcase_45 AC 40 ms
4,380 KB
testcase_46 AC 42 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int msb(int x) {
  x = x & 0xFFFF0000 ? x & 0xFFFF0000 : x;
  x = x & 0xFF00FF00 ? x & 0xFF00FF00 : x;
  x = x & 0xF0F0F0F0 ? x & 0xF0F0F0F0 : x;
  x = x & 0xCCCCCCCC ? x & 0xCCCCCCCC : x;
  x = x & 0xAAAAAAAA ? x & 0xAAAAAAAA : x;
  return x;
}

int mgcd(int a, int b) {
  if(a > b) swap(a, b);
  if(a == 0) return b;
  ll a0 = a;
  while(msb(a) != msb(b)) a <<= 1;
  return mgcd(a ^ b, a0);
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<ll> cnt(112345);
  ll sum = 0;
  ll g = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
    g = mgcd(g, a);
    sum += a;
    if(cnt[a] == n) {
      cout << n << endl;
      return 0;
    }
  }
  
  ll ans = 1e18;
  for(ll t = 1; t < 1 << 20; t++) {
    ll i = 0;
    for(int k = 0; k < 20; k++) if(t & (1 << k)) {
      i ^= g << k;
    }
    ll res = sum;
    for(ll j = i; j <= 100000; j += i) {
      res -= cnt[j] * j;
      res += cnt[j] * j / i;
    }
    ans = min(ans, res);
  }

  cout << ans << endl;
  return 0;
}
0