結果

問題 No.937 Ultra Sword
ユーザー 👑 emthrmemthrm
提出日時 2020-02-25 02:01:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 3,000 ms
コード長 2,458 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 212,552 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2024-04-21 00:00:46
合計ジャッジ時間 10,654 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,248 KB
testcase_01 AC 48 ms
9,600 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 186 ms
5,376 KB
testcase_06 AC 308 ms
14,080 KB
testcase_07 AC 329 ms
14,336 KB
testcase_08 AC 168 ms
12,800 KB
testcase_09 AC 136 ms
12,416 KB
testcase_10 AC 355 ms
14,464 KB
testcase_11 AC 73 ms
10,112 KB
testcase_12 AC 171 ms
10,112 KB
testcase_13 AC 170 ms
10,112 KB
testcase_14 AC 185 ms
10,240 KB
testcase_15 AC 150 ms
10,112 KB
testcase_16 AC 51 ms
9,728 KB
testcase_17 AC 60 ms
9,984 KB
testcase_18 AC 160 ms
10,240 KB
testcase_19 AC 114 ms
10,240 KB
testcase_20 AC 107 ms
10,112 KB
testcase_21 AC 318 ms
15,744 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 48 ms
9,472 KB
testcase_24 AC 362 ms
5,376 KB
testcase_25 AC 157 ms
5,376 KB
testcase_26 AC 242 ms
5,376 KB
testcase_27 AC 164 ms
5,376 KB
testcase_28 AC 171 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 240 ms
5,376 KB
testcase_31 AC 301 ms
5,376 KB
testcase_32 AC 137 ms
5,376 KB
testcase_33 AC 216 ms
5,376 KB
testcase_34 AC 34 ms
5,376 KB
testcase_35 AC 19 ms
5,376 KB
testcase_36 AC 145 ms
5,376 KB
testcase_37 AC 16 ms
5,376 KB
testcase_38 AC 162 ms
5,376 KB
testcase_39 AC 12 ms
5,376 KB
testcase_40 AC 199 ms
5,376 KB
testcase_41 AC 48 ms
5,376 KB
testcase_42 AC 147 ms
5,376 KB
testcase_43 AC 139 ms
5,376 KB
testcase_44 AC 58 ms
5,376 KB
testcase_45 AC 92 ms
5,376 KB
testcase_46 AC 100 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
vector<T> divisor(T val) {
  vector<T> res;
  for (T i = 1; i * i <= val; ++i) {
    if (val % i == 0) {
      res.emplace_back(i);
      if (i * i != val) res.emplace_back(val / i);
    }
  }
  sort(ALL(res));
  return res;
}

int main() {
  const int N = 17;
  int n; cin >> n;
  ll sum = 0;
  map<int, ll> mp;
  bitset<N> a;
  {
    int ai; cin >> ai;
    sum += ai;
    a = ai;
    vector<int> d = divisor(ai);
    for (int e : d) mp[e] += ai - ai / e;
  }
  int msb = N - 1;
  for (; msb >= 0; --msb) {
    if (a.test(msb)) break;
  }
  while (--n) {
    int ai; cin >> ai;
    sum += ai;
    vector<int> d = divisor(ai);
    for (int e : d) mp[e] += ai - ai / e;
    bitset<N> bit = ai;
    int ai_msb = N - 1;
    for (; ai_msb >= 0; --ai_msb) {
      if (bit.test(ai_msb)) break;
    }
    if (ai_msb > msb) {
      swap(a, bit);
      swap(msb, ai_msb);
    }
    while (bit.any()) {
      a = a ^ (bit << (msb - ai_msb));
      for (; msb >= 0; --msb) {
        if (a.test(msb)) break;
      }
      if (msb < ai_msb) {
        swap(a, bit);
        swap(msb, ai_msb);
      }
    }
  }
  set<int> mul;
  FOR(i, 1, 1 << (N - msb)) {
    bitset<N> bit;
    REP(j, N - msb) {
      if (i >> j & 1) bit ^= a << j;
    }
    mul.emplace(int(bit.to_ulong()));
  }
  ll ans = sum;
  for (auto pr : mp) {
    if (mul.count(pr.first) == 1) chmin(ans, sum - pr.second);
  }
  cout << ans << '\n';
  return 0;
}
0