結果

問題 No.937 Ultra Sword
ユーザー face4face4
提出日時 2019-11-30 10:21:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 442 ms / 3,000 ms
コード長 1,026 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 77,504 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 03:04:19
合計ジャッジ時間 9,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,816 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 9 ms
6,944 KB
testcase_03 AC 10 ms
6,944 KB
testcase_04 AC 10 ms
6,940 KB
testcase_05 AC 371 ms
6,940 KB
testcase_06 AC 323 ms
6,940 KB
testcase_07 AC 364 ms
6,944 KB
testcase_08 AC 159 ms
6,944 KB
testcase_09 AC 121 ms
6,940 KB
testcase_10 AC 395 ms
6,940 KB
testcase_11 AC 44 ms
6,940 KB
testcase_12 AC 192 ms
6,940 KB
testcase_13 AC 182 ms
6,944 KB
testcase_14 AC 210 ms
6,940 KB
testcase_15 AC 154 ms
6,940 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 174 ms
6,940 KB
testcase_19 AC 108 ms
6,944 KB
testcase_20 AC 86 ms
6,944 KB
testcase_21 AC 418 ms
6,944 KB
testcase_22 AC 10 ms
6,940 KB
testcase_23 AC 9 ms
6,944 KB
testcase_24 AC 442 ms
6,940 KB
testcase_25 AC 274 ms
6,940 KB
testcase_26 AC 242 ms
6,944 KB
testcase_27 AC 228 ms
6,944 KB
testcase_28 AC 282 ms
6,940 KB
testcase_29 AC 16 ms
6,944 KB
testcase_30 AC 206 ms
6,944 KB
testcase_31 AC 311 ms
6,944 KB
testcase_32 AC 183 ms
6,944 KB
testcase_33 AC 309 ms
6,940 KB
testcase_34 AC 55 ms
6,944 KB
testcase_35 AC 28 ms
6,940 KB
testcase_36 AC 258 ms
6,944 KB
testcase_37 AC 31 ms
6,940 KB
testcase_38 AC 205 ms
6,940 KB
testcase_39 AC 18 ms
6,940 KB
testcase_40 AC 232 ms
6,940 KB
testcase_41 AC 94 ms
6,944 KB
testcase_42 AC 187 ms
6,940 KB
testcase_43 AC 178 ms
6,944 KB
testcase_44 AC 71 ms
6,940 KB
testcase_45 AC 115 ms
6,944 KB
testcase_46 AC 132 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<numeric>
#include<cmath>
using namespace std;
typedef long long ll;

int gcd(int x, int y){
    if(x < y)   swap(x, y);
    if(y == 0)  return x;
    int cp = y;
    while((int)(log2(x)) > (int)(log2(y)))   y <<= 1;
    return gcd(cp, x^y);
}

int main(){
    int n;
    cin >> n;
    
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];

    ll ans = accumulate(v.begin(), v.end(), 0ll);

    vector<ll> d(100001, 0);
    for(int i = 0; i < n; i++){
        ll x = v[i];
        for(ll i = 1; i*i <= x; i++){
            if(x%i) continue;
            d[i] += x-x/i;
            if(i*i != x)    d[x/i] += x-i;
        }
    }

    int g = 0;
    for(int i = 0; i < n; i++)  g = gcd(g, v[i]);

    ll sub = 0;
    for(int i = 1; i < 1<<17; i++){
        ll make = 0;
        for(int j = 0; j < 17; j++){
            if((i>>j)&1)    make ^= (ll)g<<j;
        }
        if(make <= 100000) sub = max(sub, d[make]);
    }
    
    cout << ans-sub << endl;
    return 0;
}
0