結果

問題 No.937 Ultra Sword
ユーザー finefine
提出日時 2019-11-29 23:41:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,603 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 174,012 KB
実行使用メモリ 4,964 KB
最終ジャッジ日時 2023-08-13 09:19:48
合計ジャッジ時間 4,326 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 22 ms
4,436 KB
testcase_06 AC 25 ms
4,764 KB
testcase_07 AC 27 ms
4,964 KB
testcase_08 AC 17 ms
4,400 KB
testcase_09 AC 15 ms
4,428 KB
testcase_10 AC 29 ms
4,844 KB
testcase_11 AC 6 ms
4,384 KB
testcase_12 AC 19 ms
4,384 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 21 ms
4,384 KB
testcase_15 AC 16 ms
4,384 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,384 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 11 ms
4,384 KB
testcase_20 AC 10 ms
4,384 KB
testcase_21 AC 27 ms
4,952 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 20 ms
4,580 KB
testcase_25 AC 31 ms
4,760 KB
testcase_26 AC 24 ms
4,624 KB
testcase_27 AC 23 ms
4,580 KB
testcase_28 AC 31 ms
4,688 KB
testcase_29 AC 14 ms
4,380 KB
testcase_30 AC 19 ms
4,788 KB
testcase_31 AC 29 ms
4,960 KB
testcase_32 AC 19 ms
4,552 KB
testcase_33 AC 30 ms
4,876 KB
testcase_34 AC 15 ms
4,700 KB
testcase_35 AC 11 ms
4,452 KB
testcase_36 AC 29 ms
4,572 KB
testcase_37 AC 14 ms
4,628 KB
testcase_38 AC 22 ms
4,580 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 23 ms
4,700 KB
testcase_41 AC 15 ms
4,448 KB
testcase_42 AC 19 ms
4,516 KB
testcase_43 AC 20 ms
4,380 KB
testcase_44 AC 16 ms
4,432 KB
testcase_45 AC 16 ms
4,556 KB
testcase_46 AC 19 ms
4,440 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 100000; // 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, vector< vector<int> >& v, bool is_extended = false) {
    int rank = 0;
    for (int i = 0; i < MAX_ROW; i++) v[i].push_back(i);

    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;
        swap(A[pivot], A[rank]);
        swap(ids[pivot], ids[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) {
                A[row] ^= A[rank];
                for (int x : v[ids[rank]]) v[ids[row]].push_back(x);
            }
        }
        ++rank;
    }
    return rank;
}

constexpr ll MAXV = 100000;

ll cnt[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;
    ll maxa = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        maxa = max(maxa, 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 <= maxa; i++) {
        for (int j = i; (j += i) <= maxa; ) {
            cnt[i] += cnt[j];
        }
    }

    vector<int> ids(MAX_ROW);
    iota(ids.begin(), ids.end(), 0);
    vector< vector<int> > v(MAX_ROW);
    int rank = GaussJordan(A, ids, v);

    ll ans = sum;
    for (int i = 1; i <= maxa; i++) {
        vector<int> hoge(MAX_ROW, false);
        for (int j = 0; j < MAX_ROW; j++) {
            hoge[j] = ((i & (1 << j)) > 0);
        }

        bool f = true;
        for (int jj = rank; jj < MAX_ROW; jj++) {
            int j = ids[jj];
            int val = 0;
            for (int k : v[j]) {
                val ^= hoge[k];
            }
            if (val) {
                f = false;
                break;
            }
        }

        if (!f) continue;

        ans = min(ans, sum - cnt[i] + cnt[i] / i);
    }
    cout << ans << "\n";
    return 0;
}
0