結果
| 問題 |
No.937 Ultra Sword
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-29 23:37:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,540 bytes |
| コンパイル時間 | 1,759 ms |
| コンパイル使用メモリ | 175,672 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-21 03:01:01 |
| 合計ジャッジ時間 | 3,879 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 24 |
ソースコード
#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 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];
v[ids[row]].push_back(ids[rank]);
}
}
++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 = hoge[j];
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;
}