結果

問題 No.937 Ultra Sword
ユーザー 👑 emthrmemthrm
提出日時 2020-02-25 01:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,970 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 213,612 KB
実行使用メモリ 20,864 KB
最終ジャッジ日時 2024-04-20 23:47:50
合計ジャッジ時間 10,217 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 165 ms
5,376 KB
testcase_06 AC 243 ms
15,232 KB
testcase_07 AC 261 ms
15,488 KB
testcase_08 AC 117 ms
12,032 KB
testcase_09 AC 87 ms
10,624 KB
testcase_10 AC 285 ms
15,872 KB
testcase_11 AC 26 ms
5,376 KB
testcase_12 AC 119 ms
5,376 KB
testcase_13 AC 116 ms
5,376 KB
testcase_14 AC 134 ms
5,376 KB
testcase_15 AC 99 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 13 ms
5,376 KB
testcase_18 AC 107 ms
5,376 KB
testcase_19 AC 64 ms
5,376 KB
testcase_20 AC 56 ms
5,376 KB
testcase_21 AC 276 ms
20,864 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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 ans = 0;
  map<int, ll> mp;
  bitset<N> a;
  {
    int ai; cin >> ai;
    ans += 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;
    ans += 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);
      }
    }
  }
  map<ll, vector<int> > rev;
  for (auto pr : mp) rev[pr.second].emplace_back(pr.first);
  auto it = prev(rev.end());
  do {
    const vector<int> &ds = it->second;
    for (int e : ds) {
      bitset<N> bit = e, mul = a;
      int bit_msb = N - 1, mul_msb = msb;
      for (; bit_msb >= 0; --bit_msb) {
        if (bit.test(bit_msb)) break;
      }
      if (bit_msb < msb) continue;
      while (mul.any()) {
        bit = bit ^ (mul << (bit_msb - mul_msb));
        for (; bit_msb >= 0; --bit_msb) {
          if (bit.test(bit_msb)) break;
        }
        if (bit_msb < mul_msb) {
          swap(bit, mul);
          swap(bit_msb, mul_msb);
        }
      }
      if (bit == a) {
        cout << ans - it->first << '\n';
        return 0;
      }
    }
  } while (it != rev.begin());
  cout << ans << '\n';
  return 0;
}
0