結果

問題 No.937 Ultra Sword
ユーザー tonyu0tonyu0
提出日時 2019-12-01 11:42:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 3,000 ms
コード長 1,027 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 88,204 KB
実行使用メモリ 9,640 KB
最終ジャッジ日時 2023-08-13 10:31:44
合計ジャッジ時間 7,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 140 ms
4,380 KB
testcase_06 AC 238 ms
7,956 KB
testcase_07 AC 261 ms
8,100 KB
testcase_08 AC 110 ms
6,756 KB
testcase_09 AC 88 ms
6,100 KB
testcase_10 AC 293 ms
8,384 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 107 ms
4,380 KB
testcase_13 AC 105 ms
4,380 KB
testcase_14 AC 120 ms
4,380 KB
testcase_15 AC 89 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 100 ms
4,380 KB
testcase_19 AC 56 ms
4,380 KB
testcase_20 AC 49 ms
4,376 KB
testcase_21 AC 269 ms
9,640 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 206 ms
4,376 KB
testcase_25 AC 133 ms
4,376 KB
testcase_26 AC 212 ms
4,380 KB
testcase_27 AC 143 ms
4,376 KB
testcase_28 AC 149 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 212 ms
4,380 KB
testcase_31 AC 258 ms
4,380 KB
testcase_32 AC 122 ms
4,380 KB
testcase_33 AC 183 ms
4,376 KB
testcase_34 AC 28 ms
4,376 KB
testcase_35 AC 17 ms
4,376 KB
testcase_36 AC 123 ms
4,380 KB
testcase_37 AC 13 ms
4,376 KB
testcase_38 AC 141 ms
4,376 KB
testcase_39 AC 10 ms
4,376 KB
testcase_40 AC 169 ms
4,380 KB
testcase_41 AC 41 ms
4,380 KB
testcase_42 AC 129 ms
4,376 KB
testcase_43 AC 119 ms
4,380 KB
testcase_44 AC 52 ms
4,376 KB
testcase_45 AC 80 ms
4,376 KB
testcase_46 AC 88 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<int> A(N);
  map<int, long long> mp;

  int g = 0;
  long long sum = 0;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
    // calc gcd
    int a = g, b = A[i];
    while(true) {
      if(a < b) swap(a, b);
      if(b == 0) break;
      int c = b;
      while(__builtin_clz(a) != __builtin_clz(c)) c <<= 1;
      c = a ^ c;
      a = b, b = c;
    }
    g = a;

    // calc divisors of A[i]
    int n = A[i];
    for(int j = 1; j * j <= n; ++j) {
      if(n % j == 0) {
        mp[j] += A[i] - n / j;
        if(n / j != j) mp[n / j] += A[i] - j;
      }
    }
  }

  long long ans = 0;
  for(auto m : mp) {
    int div = m.first;
    while(div >= g) {
      int h = g;
      while(__builtin_clz(div) != __builtin_clz(h)) h <<= 1;
      div ^= h;
    }
    if(div == 0) ans = max(ans, m.second);
  }

  cout << sum - ans << '\n';
  return 0;
}
0