結果
問題 | No.917 Make One With GCD |
ユーザー | ngtkana |
提出日時 | 2019-10-25 22:50:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 4,200 bytes |
コンパイル時間 | 2,453 ms |
コンパイル使用メモリ | 224,076 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:05:30 |
合計ジャッジ時間 | 3,645 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 15 ms
6,944 KB |
testcase_07 | AC | 11 ms
6,944 KB |
testcase_08 | AC | 7 ms
6,940 KB |
testcase_09 | AC | 16 ms
6,940 KB |
testcase_10 | AC | 17 ms
6,944 KB |
testcase_11 | AC | 15 ms
6,940 KB |
testcase_12 | AC | 19 ms
6,944 KB |
testcase_13 | AC | 13 ms
6,940 KB |
testcase_14 | AC | 15 ms
6,944 KB |
testcase_15 | AC | 15 ms
6,940 KB |
testcase_16 | AC | 14 ms
6,940 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | AC | 6 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 4 ms
6,944 KB |
testcase_21 | AC | 6 ms
6,940 KB |
testcase_22 | AC | 4 ms
6,940 KB |
testcase_23 | AC | 8 ms
6,940 KB |
testcase_24 | AC | 6 ms
6,940 KB |
testcase_25 | AC | 11 ms
6,940 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
ソースコード
#define STOPIT #include <bits/stdc++.h> #define loop(n) for (lint ngtkana_is_genius = 0; ngtkana_is_genius < lint(n); ngtkana_is_genius++) #define rep(i, begin, end) for(lint i = lint(begin); i < lint(end); i++) #define all(v) v.begin(), v.end() #define rand(l, r) std::uniform_int_distribution<>(l, r)(mt) using lint = long long; auto mt = std::mt19937_64(std::random_device{}()); auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;}; auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;}; void debug_impl() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail){ std::cerr << " " << head; debug_impl(tail...); } #ifndef STOPIT #define debug(...)\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha; #else #define debug 0; #endif template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr> std::istream& operator>> (std::istream& is, Container& v) { for (auto & x : v) { is >> x; } return is; } template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr > std::ostream& operator<< (std::ostream& os, Container const& v) { os << "{"; for (auto it = v.begin(); it != v.end(); it++) {os << (it != v.begin() ? "," : "") << *it;} return os << "}"; } template < template < typename ... > class Tuple, typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>) { (void)std::initializer_list<lint>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; } template < template < typename ... > class Tuple, typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple) { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); } template < template < typename ... > class Tuple, typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>) { os << "("; (void)std::initializer_list<lint>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; } template < template < typename ... > class Tuple, typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple) { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); } inline auto divisors(lint x) { std::vector< lint > ret; std::stack < lint > stk; for (auto i = 1; i * i <= x; i++) { if (x % i == 0) { ret.emplace_back(i); if (i * i < x) { stk.emplace(x / i); } } } while (!stk.empty()) { ret.emplace_back(stk.top()), stk.pop(); } return ret; } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); lint n; std::cin >> n; std::vector< lint > a(n); std::cin >> a; std::sort(all(a)); std::map< lint, lint > map; for (auto x : a) { auto divs = divisors(x); for (auto y : divs) { map[y]++; } } std::vector< lint > pow2(n + 1, 1); rep(i, 1, n + 1) { pow2.at(i) = pow2.at(i - 1) * 2; } auto cal = [&] (auto k) { return pow2.at(k) - 1; }; std::map< lint, lint, std::greater< lint > > dp; for (auto pair : map) { lint x, k; std::tie(x, k) = pair; dp[x] += cal(k); } debug(dp); auto now = std::numeric_limits< lint >::max(); while (1 < now) { auto lb = dp.upper_bound(now); lint x = lb->first; lint val = lb->second; debug(x, val); for (auto d : divisors(x)) { if (d == x) continue; dp[d] -= val; } now = x; } debug(dp); lint ret = dp.at(1); std::cout << ret << std::endl; return 0; }