結果
問題 |
No.937 Ultra Sword
|
ユーザー |
![]() |
提出日時 | 2019-11-29 23:36:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,905 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 177,040 KB |
実行使用メモリ | 15,652 KB |
最終ジャッジ日時 | 2024-11-21 03:01:53 |
合計ジャッジ時間 | 52,174 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 23 TLE * 7 |
ソースコード
//#define _GLIBCXX_DEBUG #include "bits/stdc++.h" using namespace std; //------------------------------- Type Names -------------------------------// using i64 = int_fast64_t; using seika = string; //{akari : 1D, yukari : 2D, maki : 3D} vector template <class kizuna> using akari = vector<kizuna>; template <class yuzuki> using yukari = akari<akari<yuzuki>>; template <class tsurumaki> using maki = akari<yukari<tsurumaki>>; //{akane : ascending order, aoi : decending order} priority queue template <class kotonoha> using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>; template <class kotonoha> using aoi = priority_queue<kotonoha>; //------------------------------- Libraries --------------------------------// //------------------------------- Dubug Functions ---------------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &... rest) { cout << first << ' '; print(rest...); } //------------------------------- Solver ------------------------------------// void solve() { int n; cin >> n; akari<int> as(n), bs; for (int i = 0; i < n; i++) { cin >> as[i]; } bs = as; for (int d = 0; d < 20; d++) { int p = -1; for (int i = 0; i < n; i++) { if (as[i] >> d & 1) { p = i; break; } } if (p == -1) { continue; } if (p) { swap(as[p], as[0]); } for (int i = 0; i < n; i++) { if (i == p || !(as[i] >> d & 1)) { continue; } as[i] ^= as[p]; } } int lsb = -1; for (int d = 0; d < 20; d++) for (int i = 0; i < n; i++) { //cout << bitset<20>(as[i]) << endl; if (as[i] >> d & 1) { lsb = d; i = n; d = 20; } } //print(lsb); int mask = (1 << lsb) - 1; set<int> fs; for (int i = 0; i < n; i++) { for (int f = 1; f * f <= bs[i]; f++) { if (bs[i] % f == 0) { fs.insert(f); if (f * f != bs[i]) { fs.insert(bs[i] / f); } } } } i64 ans = 1e15; for (int f : fs) { if (mask & f) { continue; } i64 res = 0; for (int i = 0; i < n; i++) { if (bs[i] % f == 0) { res += bs[i] / f; } else { res += bs[i]; } } ans = min(ans, res); } cout << ans << endl; } int main() { solve(); return 0; }