結果
問題 | No.937 Ultra Sword |
ユーザー | Pachicobue |
提出日時 | 2019-11-29 22:48:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,786 bytes |
コンパイル時間 | 2,380 ms |
コンパイル使用メモリ | 216,584 KB |
実行使用メモリ | 19,740 KB |
最終ジャッジ日時 | 2024-11-21 02:39:34 |
合計ジャッジ時間 | 6,055 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
6,820 KB |
testcase_01 | WA | - |
testcase_02 | AC | 9 ms
6,816 KB |
testcase_03 | AC | 14 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 101 ms
13,068 KB |
testcase_08 | WA | - |
testcase_09 | AC | 76 ms
10,576 KB |
testcase_10 | WA | - |
testcase_11 | AC | 77 ms
11,152 KB |
testcase_12 | AC | 124 ms
18,616 KB |
testcase_13 | AC | 119 ms
18,380 KB |
testcase_14 | AC | 130 ms
19,740 KB |
testcase_15 | AC | 113 ms
16,980 KB |
testcase_16 | AC | 58 ms
9,600 KB |
testcase_17 | AC | 61 ms
10,104 KB |
testcase_18 | AC | 118 ms
17,780 KB |
testcase_19 | AC | 93 ms
14,240 KB |
testcase_20 | AC | 87 ms
13,564 KB |
testcase_21 | WA | - |
testcase_22 | AC | 13 ms
6,820 KB |
testcase_23 | AC | 54 ms
9,472 KB |
testcase_24 | AC | 41 ms
7,668 KB |
testcase_25 | AC | 42 ms
8,752 KB |
testcase_26 | AC | 36 ms
7,824 KB |
testcase_27 | AC | 36 ms
7,976 KB |
testcase_28 | AC | 41 ms
8,348 KB |
testcase_29 | AC | 4 ms
6,816 KB |
testcase_30 | AC | 30 ms
7,240 KB |
testcase_31 | AC | 47 ms
8,900 KB |
testcase_32 | AC | 28 ms
7,204 KB |
testcase_33 | AC | 46 ms
9,040 KB |
testcase_34 | AC | 10 ms
6,816 KB |
testcase_35 | AC | 6 ms
6,816 KB |
testcase_36 | AC | 41 ms
8,388 KB |
testcase_37 | AC | 7 ms
6,820 KB |
testcase_38 | AC | 31 ms
7,580 KB |
testcase_39 | AC | 5 ms
6,820 KB |
testcase_40 | AC | 37 ms
8,076 KB |
testcase_41 | AC | 16 ms
6,816 KB |
testcase_42 | AC | 29 ms
7,336 KB |
testcase_43 | AC | 28 ms
7,080 KB |
testcase_44 | AC | 13 ms
6,816 KB |
testcase_45 | AC | 18 ms
6,820 KB |
testcase_46 | WA | - |
ソースコード
#include <bits/stdc++.h> // created [2019/11/29] 22:16:35 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); } template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); } template<typename T> constexpr T msbp1(const T u) { return log2p1(u); } template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); } template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; } template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); } template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); } template<typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); } template<typename T> void bset(T& mask, const usize ind) { mask |= (static_cast<T>(1) << ind); } template<typename T> void breset(T& mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); } template<typename T> void bflip(T& mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); } template<typename T> void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template<typename T> T read() { T v; return std::cin >> v, v; } template<typename T, typename... Args> auto read(const usize size, Args... args) { std::vector<decltype(read<T>(args...))> ans(size); for (usize i = 0; i < size; i++) { ans[i] = read<T>(args...); } return ans; } template<typename... Types> auto reads() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; } # define SHOW(...) static_cast<void>(0) template<typename T> std::vector<T> make_v(const usize size, const T v) { return std::vector<T>(size, v); } template<typename... Args> auto make_v(const usize size, Args... args) { return std::vector<decltype(make_v(args...))>(size, make_v(args...)); } template<typename T> std::vector<T> divisors(const T n) { std::vector<T> head, tail; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { head.push_back(i); if (i * i != n) { tail.push_back(n / i); } } } for (auto it = tail.rbegin(); it != tail.rend(); it++) { head.push_back(*it); } return head; } template<usize column> class bit_matrix { public: bit_matrix(const usize row) : row{row}, table(row) {} bit_matrix(const bit_matrix& m) : row{m.row}, table{m.table} {} bit_matrix& operator=(const bit_matrix& m) { assert(row == m.row), assert(column == m.column); for (usize i = 0; i < row; i++) { table[i] = m[i]; } return *this; } const std::bitset<column>& operator[](const usize r) const { return assert(r < row), table[r]; } std::bitset<column>& operator[](const usize r) { return assert(r < row), table[r]; } friend bit_matrix operator+(const bit_matrix& m) { return m; } friend bit_matrix operator^(const bit_matrix& m1, const bit_matrix& m2) { assert(m1.row == m2.row); bit_matrix ans(m1.row); for (usize i = 0; i < m1.row; i++) { ans[i] = m1.table[i] ^ m2.table[i]; } return ans; } template<usize col2> friend bit_matrix operator*(const bit_matrix& m1, const bit_matrix<col2>& m2) { assert(column == m2.row); bit_matrix<col2> ans(m1.row); for (usize i = 0; i < m1.row; i++) { for (usize j = 0; j < column; j++) { if (not m1.table[i][j]) { continue; } ans[i] ^= m2.table[j]; } } return ans; } friend bit_matrix operator^(const bit_matrix& m, const unsigned long long n) { return assert(m.row == m.column), n == 0 ? bit_matrix::id(m.row) : n % 2 == 1 ? m*(m ^ (n - 1)) : ((m * m) ^ (n / 2)); } friend bit_matrix& operator^=(bit_matrix& m1, const bit_matrix& m2) { assert(m1.row == m2.row), assert(m1.column == m2.column); for (usize i = 0; i < m1.row; i++) { m1.table[i] ^= m2.table[i]; } return m1; } friend bit_matrix& operator*=(bit_matrix& m1, const bit_matrix& m2) { return m1 = m1 * m2; } friend bit_matrix& operator^=(bit_matrix& m, const unsigned long long n) { return m = m ^ n; } friend std::ostream& operator<<(std::ostream& os, const bit_matrix& m) { os << "[\n"; for (usize i = 0; i < m.row; i++) { os << "[" << m[i] << "]\n"; } return (os << "]\n"); } static bit_matrix id(const usize n) { bit_matrix ans(n); for (usize i = 0; i < n; i++) { ans[i].set(i); } return ans; } usize row; private: std::vector<std::bitset<column>> table; }; template<usize column> bit_matrix<column> gauss_jordan(bit_matrix<column> mat) { for (usize r = 0, ci = 0; ci < column; ci++) { const usize c = column - ci - 1; if (r == mat.row) { break; } usize piv = r; for (; piv < mat.row and not mat[piv][c]; piv++) {} if (piv == mat.row) { continue; } std::swap(mat[piv], mat[r]); for (usize j = 0; j < mat.row; j++) { if (j == r) { continue; } if (mat[j][c]) { mat[j] ^= mat[r]; } } r++; } return mat; } int main() { const int N = read<int>(); const auto A = read<int>(N); constexpr uint lg = 17; std::vector<uint> as; for (uint i = 0; i < N; i++) { for (uint a = A[i]; a <= 100000; a *= 2) { as.push_back(a); } } bit_matrix<lg> m(as.size()); for (int r = 0; r < as.size(); r++) { m[r] = as[r]; } const auto base = gauss_jordan(m); std::vector<uint> bs; for (int i = 0; i < as.size(); i++) { if (base[i].to_ullong() == 0) { break; } bs.push_back(base[i].to_ulong()); } // SHOW(bs); const int bn = bs.size(); std::set<int> ok; const int mask = 1 << bn; for (int m = 0; m < mask; m++) { uint a = 0; for (int i = 0; i < bn; i++) { if (not btest(m, i)) { continue; } a ^= bs[i]; } if (a <= 100000) { ok.insert(a); } } // SHOW(ok); std::vector<ll> S(100001, 0); for (int i = 0; i < N; i++) { S[A[i]] += A[i]; } std::vector<ll> minus(100001, 0); for (const int i : ok) { if (i == 0) { continue; } for (int j = i; j < 100000; j += i) { minus[i] += S[j] - S[j] / i; } } const ll sum = std::accumulate(A.begin(), A.end(), 0LL); std::cout << sum - *std::max_element(minus.begin(), minus.end()) << std::endl; return 0; }