結果
問題 | No.5020 Averaging |
ユーザー |
![]() |
提出日時 | 2024-02-25 15:14:43 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 4,199 bytes |
コンパイル時間 | 2,931 ms |
コンパイル使用メモリ | 256,172 KB |
実行使用メモリ | 6,548 KB |
スコア | 15,490,811 |
最終ジャッジ日時 | 2024-02-25 15:14:48 |
合計ジャッジ時間 | 4,599 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#if __INCLUDE_LEVEL__ == 0#include __BASE_FILE__namespace {constexpr int K = 16;void solve() {int n;scan(n);std::vector<i64> a(n), b(n);for (const int i : rep(n)) {scan(a[i], b[i]);a[i] >>= 1;b[i] >>= 1;}std::vector<int> p(n);std::iota(p.begin(), p.end(), 0);i64 s = 0;i64 t = 0;for (const int i : rep(K)) {s += a[i];t += b[i];}const auto evaluate = [&] {constexpr i64 H = (500'000'000'000'000'000 >> 1) * K;return std::max(std::abs(s - H), std::abs(t - H));};i64 cur = evaluate();for (int _ = 0; _--;) {const int i = randint(1, K - 1);const int j = randint(K, n - 1);s += a[p[j]] - a[p[i]];t += b[p[j]] - b[p[i]];std::swap(p[i], p[j]);const i64 nxt = evaluate();if (cur < nxt) {std::swap(p[i], p[j]);s -= a[p[j]] - a[p[i]];t -= b[p[j]] - b[p[i]];} else {cur = nxt;}}print(K - 1);for (int k = 1; k < K; k *= 2) {for (int i = 0; i < K; i += k * 2) {print(p[i] + 1, p[i + k] + 1);}}}} // namespaceint main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout << std::setprecision(DBL_DECIMAL_DIG);solve();}#else // __INCLUDE_LEVEL__#include <bits/stdc++.h>template <class T, class U = T>bool chmin(T& x, U&& y) {return y < x && (x = std::forward<U>(y), true);}template <class T, class U = T>bool chmax(T& x, U&& y) {return x < y && (x = std::forward<U>(y), true);}template <std::signed_integral T = int>T inf() {T ret;std::memset(&ret, 0x3f, sizeof(ret));return ret;}template <std::floating_point T>T inf() {return std::numeric_limits<T>::infinity();}template <class T>concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;template <class T>concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;namespace std {istream& operator>>(istream& is, Range auto&& r) {for (auto&& e : r) {is >> e;}return is;}istream& operator>>(istream& is, Tuple auto&& t) {return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);}ostream& operator<<(ostream& os, Range auto&& r) {for (string_view sep = ""; auto&& e : r) {os << exchange(sep, " ") << e;}return os;}ostream& operator<<(ostream& os, Tuple auto&& t) {const auto f = [&](auto&... xs) -> ostream& {[[maybe_unused]] string_view sep = "";((os << exchange(sep, " ") << xs), ...);return os;};return apply(f, t);}} // namespace stdvoid scan(auto&&... xs) { std::cin >> std::tie(xs...); }void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }template <class F>class fix {public:explicit fix(F f) : f_(std::move(f)) {}decltype(auto) operator()(auto&&... xs) const {return f_(std::ref(*this), std::forward<decltype(xs)>(xs)...);}private:F f_;};inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); }inline auto rep(int n) { return rep(0, n); }inline auto rep1(int l, int r) { return rep(l, r + 1); }inline auto rep1(int n) { return rep(1, n + 1); }namespace ranges = std::ranges;namespace views = std::views;using i64 = std::int64_t;namespace xorshift {using u64 = std::uint64_t;using u128 = ::__uint128_t;inline u64 x = std::chrono::steady_clock::now().time_since_epoch().count();inline u64 next() {x ^= x << 7;x ^= x >> 9;return x;}int randint(int a, int b) {const u64 m = static_cast<u64>(b) - static_cast<u64>(a) + 1;return a + static_cast<int>(u128{next()} * m >> 64);}template <std::ranges::random_access_range R>void shuffle(R&& r) {const int n = static_cast<int>(std::ranges::size(r));if (n < 2) {return;}for (const int i : std::views::iota(1, n)) {if (const int j = randint(0, i); j < i) {std::ranges::swap(r[i], r[j]);}}}double uniform() { return static_cast<double>(next()) / static_cast<double>(UINT64_MAX); }double uniform(double a, double b) { return a + (b - a) * uniform(); }} // namespace xorshiftusing xorshift::randint;using xorshift::shuffle;using xorshift::uniform;#endif // __INCLUDE_LEVEL__