結果

問題 No.937 Ultra Sword
ユーザー fine
提出日時 2019-11-29 23:19:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,073 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 173,692 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-11-21 02:47:59
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

// http://drken1215.hatenablog.com/entry/2019/03/20/202800
const int MAX_ROW = 17; // to be set appropriately
const int MAX_COL = 1000000; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, vector<int>& ids, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        ids.push_back(col);
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

constexpr ll MAXV = 100000;

ll cnt[MAXV + 1];
bool ok[MAXV + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    BitMatrix A(MAX_ROW, n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] += a[i];
        sum += a[i];

        for (int j = 0; j < MAX_ROW; j++) {
            if (a[i] & (1 << j)) A[j].set(i);
        }
    }

    for (int i = 1; i <= MAXV; i++) {
        for (int j = i; (j += i) <= MAXV; ) {
            cnt[i] += cnt[j];
        }
    }

    vector<int> ids;
    int rank = GaussJordan(A, ids);
    assert(ids.size() == rank);

    for (int i = 1; i < (1 << rank); i++) {
        ll val = 0;
        for (int j = 0; j < rank; j++) {
            if (i & (1 << j)) val ^= a[j];
        }
        ok[val] = true;
    }

    ll ans = 1e18;
    for (int i = 1; i <= MAXV; i++) {
        if (!ok[i]) continue;
        ans = min(ans, sum - cnt[i] + cnt[i] / i);
    }
    cout << ans << "\n";
    return 0;
}
0