結果

問題 No.937 Ultra Sword
ユーザー potoooooooopotoooooooo
提出日時 2019-11-29 23:33:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,603 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 179,304 KB
実行使用メモリ 21,340 KB
最終ジャッジ日時 2024-05-01 02:52:59
合計ジャッジ時間 8,518 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
14,280 KB
testcase_01 WA -
testcase_02 AC 62 ms
14,208 KB
testcase_03 AC 66 ms
14,208 KB
testcase_04 AC 65 ms
14,276 KB
testcase_05 AC 131 ms
14,656 KB
testcase_06 AC 167 ms
19,496 KB
testcase_07 AC 181 ms
19,872 KB
testcase_08 AC 117 ms
17,460 KB
testcase_09 AC 102 ms
16,896 KB
testcase_10 AC 188 ms
19,956 KB
testcase_11 AC 86 ms
15,796 KB
testcase_12 AC 146 ms
16,328 KB
testcase_13 AC 144 ms
16,384 KB
testcase_14 AC 155 ms
16,452 KB
testcase_15 AC 136 ms
16,256 KB
testcase_16 AC 65 ms
14,592 KB
testcase_17 AC 73 ms
15,272 KB
testcase_18 AC 138 ms
16,196 KB
testcase_19 AC 111 ms
16,128 KB
testcase_20 AC 108 ms
15,872 KB
testcase_21 AC 142 ms
21,340 KB
testcase_22 AC 60 ms
14,152 KB
testcase_23 AC 62 ms
14,152 KB
testcase_24 AC 222 ms
14,792 KB
testcase_25 AC 108 ms
14,660 KB
testcase_26 AC 113 ms
14,592 KB
testcase_27 AC 104 ms
14,592 KB
testcase_28 AC 111 ms
14,612 KB
testcase_29 AC 64 ms
14,276 KB
testcase_30 AC 111 ms
14,464 KB
testcase_31 AC 125 ms
14,720 KB
testcase_32 AC 96 ms
14,336 KB
testcase_33 AC 118 ms
14,720 KB
testcase_34 AC 73 ms
14,464 KB
testcase_35 AC 68 ms
14,280 KB
testcase_36 AC 106 ms
14,760 KB
testcase_37 AC 67 ms
14,208 KB
testcase_38 AC 108 ms
14,404 KB
testcase_39 AC 65 ms
14,208 KB
testcase_40 AC 107 ms
14,532 KB
testcase_41 AC 77 ms
14,260 KB
testcase_42 AC 96 ms
14,592 KB
testcase_43 AC 96 ms
14,336 KB
testcase_44 AC 79 ms
14,536 KB
testcase_45 AC 85 ms
14,276 KB
testcase_46 AC 89 ms
14,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<int> dv[100010];
long long sum[100010];

void calc_div() {
    for (int i = 2; i <= 100000; i++) {
        for (int j = i; j <= 100000; j += i) {
            dv[j].emplace_back(i);
        }
    }
}

void gj(vector<long long> &v) {
    int pv = 0; int n = v.size();
    for (int k = 16; k >= 0; k--) {
        for (int i = pv; i < n; i++) {
            if (v[i] & (1 << k)) {
                swap(v[pv], v[i]);
                break;
            }
        }
        if (v[pv] & (1 << k)) {
            for (int i = 0; i < n; i++) {
                if (i == pv) continue;
                if (v[i] & (1 << k)) {
                    v[i] ^= v[pv];
                }
            }
            pv++;
        }
        if (pv == n) break;
    }
}

int main() {
    calc_div();
    int n; cin >> n;
    long long all = 0;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; all += a[i];
        for (auto &d: dv[a[i]]) sum[d] -= a[i] - a[i] / d;
    }
    for (int i = 0; i <= 100000; i++) sum[i] += all;
    
    set<long long> s;
    for (int i = 0; i < n; i++) {
        while (a[i] < (1 << 17)) {
            s.insert(a[i]); a[i] *= 2;
        }
    }
    vector<long long> b;
    for (auto &x: s) b.emplace_back(x);
    gj(b);
    
    long long ans = 1e18;
    for (int x = 1; x <= 100000; x++) {
        int t = x;
        for (int i = 0; i < min(18, (int) b.size()); i++) {
            if ((t ^ b[i]) < t) t ^= b[i];
        }
        if (t == 0) ans = min(ans, sum[x]);
    }
    cout << ans << endl;
    return 0;
}
0