結果

問題 No.5020 Averaging
ユーザー りあんりあん
提出日時 2024-02-25 13:53:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 2,414 bytes
コンパイル時間 4,266 ms
コンパイル使用メモリ 277,724 KB
実行使用メモリ 6,676 KB
スコア 28,334,479
最終ジャッジ日時 2024-02-25 13:53:25
合計ジャッジ時間 5,971 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 3 ms
6,676 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 3 ms
6,676 KB
testcase_33 AC 3 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 3 ms
6,676 KB
testcase_37 AC 3 ms
6,676 KB
testcase_38 AC 3 ms
6,676 KB
testcase_39 AC 3 ms
6,676 KB
testcase_40 AC 3 ms
6,676 KB
testcase_41 AC 3 ms
6,676 KB
testcase_42 AC 3 ms
6,676 KB
testcase_43 AC 3 ms
6,676 KB
testcase_44 AC 3 ms
6,676 KB
testcase_45 AC 3 ms
6,676 KB
testcase_46 AC 3 ms
6,676 KB
testcase_47 AC 3 ms
6,676 KB
testcase_48 AC 3 ms
6,676 KB
testcase_49 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<sys/time.h>
// #include<atcoder/segtree>


using namespace std;

// using mint = atcoder::modint998244353;

const int M = 998244353;
const long long LM = 1LL << 60;

using P = pair<int, int>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    long long T = 500000000000000000LL;
    // auto calc = [&](int i) {
    //     return max(abs(a[0] + a[i] - T * 2), abs(b[0] + b[i] - T * 2));
    // };
    auto calc = [&](int i, int j) {
        return max(abs(a[i] + a[j] - T * 2), abs(b[i] + b[j] - T * 2));
    };
    vector<P> ans;
    while (ans.size() < 40) {
        vector<P> idx;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (calc(i, j) < calc(i, i) && calc(i, j) < calc(j, j)) {
                    idx.emplace_back(i, j);
                }
            }
        }
        if (idx.empty()) break;
        sort(idx.begin(), idx.end(), [&](const P& i, const P& j) {
            return calc(i.first, i.second) < calc(j.first, j.second);
        });
        int p = idx.front().first;
        int q = idx.front().second;
        ans.emplace_back(p, q);
        auto av = (a[p] + a[q]) / 2;
        auto bv = (b[p] + b[q]) / 2;
        a[p] = av;
        a[q] = av;
        b[p] = bv;
        b[q] = bv;
        // cerr << av << ' ' << bv << '\n';
    }
    // cerr << '\n';
    // for (int i = 0; i < n; ++i) {
    //     cerr << a[i] << ' ' << b[i] << '\n';
    // }
    while (ans.size() < 50) {
        vector<int> idx;
        for (int i = 0; i < n; ++i) {
            idx.emplace_back(i);
        }
        sort(idx.begin(), idx.end(), [&](int i, int j) {
            return calc(0, i) < calc(0, j);
        });
        int p = 0;
        int q = idx.front();
        if (q == 0) break;
        ans.emplace_back(p, q);
        auto av = (a[p] + a[q]) / 2;
        auto bv = (b[p] + b[q]) / 2;
        a[p] = av;
        a[q] = av;
        b[p] = bv;
        b[q] = bv;
    }

    if (ans.size() > 50) {
        ans.resize(50);
    }
    cout << ans.size() << '\n';
    for (auto& i : ans) {
        cout << i.first + 1 << ' ' << i.second + 1 << '\n';
    }




    return 0;
}
0