結果

問題 No.937 Ultra Sword
ユーザー lumc_lumc_
提出日時 2019-11-30 00:04:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,899 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 113,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 02:58:48
合計ジャッジ時間 3,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 15 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 40 ms
6,944 KB
testcase_07 AC 44 ms
6,940 KB
testcase_08 AC 28 ms
6,944 KB
testcase_09 AC 25 ms
6,944 KB
testcase_10 AC 47 ms
6,944 KB
testcase_11 AC 18 ms
6,940 KB
testcase_12 AC 36 ms
6,940 KB
testcase_13 AC 35 ms
6,940 KB
testcase_14 AC 39 ms
6,940 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 35 ms
6,944 KB
testcase_19 AC 27 ms
6,940 KB
testcase_20 AC 24 ms
6,940 KB
testcase_21 AC 43 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 25 ms
6,944 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 15 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 14 ms
6,944 KB
testcase_31 AC 20 ms
6,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 5 ms
6,940 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 6 ms
6,940 KB
testcase_45 WA -
testcase_46 AC 11 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;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
#define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) ((void) 42)
#define dump2D(...) ((void) 42)
#define dump1D(...) ((void) 42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}

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

ll mgcd(ll a, ll 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;
    dump(bitset<10>(a));
    if(cnt[a] == n) {
      cout << n << endl;
      return 0;
    }
  }
  
  ll ans = 1e18;
  for(ll i = g; i <= 100000; i += g) {
    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