結果

問題 No.937 Ultra Sword
ユーザー lumc_lumc_
提出日時 2019-11-30 00:10:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 3,000 ms
コード長 1,436 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 105,704 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 02:59:54
合計ジャッジ時間 4,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,812 KB
testcase_01 AC 49 ms
6,944 KB
testcase_02 AC 37 ms
6,940 KB
testcase_03 AC 38 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 12 ms
6,944 KB
testcase_06 AC 75 ms
6,944 KB
testcase_07 AC 77 ms
6,944 KB
testcase_08 AC 61 ms
6,940 KB
testcase_09 AC 57 ms
6,940 KB
testcase_10 AC 80 ms
6,944 KB
testcase_11 AC 53 ms
6,940 KB
testcase_12 AC 69 ms
6,940 KB
testcase_13 AC 69 ms
6,940 KB
testcase_14 AC 72 ms
6,940 KB
testcase_15 AC 66 ms
6,940 KB
testcase_16 AC 49 ms
6,940 KB
testcase_17 AC 49 ms
6,940 KB
testcase_18 AC 68 ms
6,940 KB
testcase_19 AC 61 ms
6,940 KB
testcase_20 AC 57 ms
6,944 KB
testcase_21 AC 76 ms
6,940 KB
testcase_22 AC 38 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 58 ms
6,944 KB
testcase_25 AC 49 ms
6,944 KB
testcase_26 AC 49 ms
6,940 KB
testcase_27 AC 48 ms
6,940 KB
testcase_28 AC 53 ms
6,940 KB
testcase_29 AC 35 ms
6,940 KB
testcase_30 AC 48 ms
6,940 KB
testcase_31 AC 53 ms
6,940 KB
testcase_32 AC 44 ms
6,944 KB
testcase_33 AC 52 ms
6,944 KB
testcase_34 AC 38 ms
6,940 KB
testcase_35 AC 36 ms
6,944 KB
testcase_36 AC 50 ms
6,944 KB
testcase_37 AC 36 ms
6,944 KB
testcase_38 AC 46 ms
6,940 KB
testcase_39 AC 35 ms
6,944 KB
testcase_40 AC 48 ms
6,944 KB
testcase_41 AC 40 ms
6,940 KB
testcase_42 AC 45 ms
6,940 KB
testcase_43 AC 45 ms
6,940 KB
testcase_44 AC 39 ms
6,940 KB
testcase_45 AC 41 ms
6,940 KB
testcase_46 AC 44 ms
6,940 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