結果

問題 No.937 Ultra Sword
ユーザー tonyu0tonyu0
提出日時 2019-12-01 10:43:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 990 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 88,648 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-05-01 03:50:58
合計ジャッジ時間 6,954 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 125 ms
6,940 KB
testcase_06 AC 202 ms
8,064 KB
testcase_07 AC 225 ms
8,204 KB
testcase_08 AC 94 ms
6,944 KB
testcase_09 AC 72 ms
6,940 KB
testcase_10 AC 252 ms
8,448 KB
testcase_11 AC 23 ms
6,944 KB
testcase_12 AC 107 ms
6,940 KB
testcase_13 AC 105 ms
6,944 KB
testcase_14 AC 116 ms
6,944 KB
testcase_15 AC 87 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 95 ms
6,940 KB
testcase_19 AC 56 ms
6,940 KB
testcase_20 AC 49 ms
6,940 KB
testcase_21 AC 248 ms
9,856 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 141 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 212 ms
6,944 KB
testcase_31 AC 257 ms
6,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 28 ms
6,940 KB
testcase_35 AC 17 ms
6,940 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 51 ms
6,944 KB
testcase_45 WA -
testcase_46 AC 90 ms
6,940 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) {
    bool ok = false;
    int div = m.first;
    while(div) {
      if(g == div) ok = true;
      div >>= 1;
    }
    if(ok) ans = max(ans, m.second);
  }

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