結果

問題 No.2353 Guardian Dogs in Spring
ユーザー hari64hari64
提出日時 2023-06-16 22:36:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,032 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 219,112 KB
実行使用メモリ 402,288 KB
最終ジャッジ日時 2023-09-06 20:58:06
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tt;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pl> vp;
typedef vector<tt> vt;
typedef vector<string> vs;

const ll INF = 1000000010;
const ll INFL = INF * INF;
const double MYPI = acos(-1);
const ld epsilon = 1e-10;

#define ovl(a, b, c, d, e, ...) e
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)
#define REP1(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, l, r) for (int i = (l); i < (r); i++)
#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))
#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))
#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define EACH1(e, a) for (auto &e : a)
#define EACH2(x, y, a) for (auto &[x, y] : a)
#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)
#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define sz(x) (ll) x.size()
#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())
#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())
#define FLG(x, i) (((x) >> (i)) & 1)
#define CNTBIT(x) __builtin_popcountll(x)
#define TOPBIT(t) (t == 0 ? -1 : 63 - __builtin_clzll(t))
#define IN(x, a, b) ((a) <= (x) && (x) < (b))

template <typename T, typename... Ts>
void OUT(const T &a, const Ts &...b) {
    cout << a;
    (cout << ... << (cout << " ", b));
    cout << endl;
}

template <typename T>
void DEBUG_(string_view name, const T &a) {
    cout << name << ": " << a << endl;
}

template <typename T>
void DEBUG_(string_view name, const vector<T> &a) {
    cout << name << ": ";
    REP(i, sz(a)) cout << a[i] << " ";
    cout << endl;
}

template <typename T1, typename T2>
bool chmax(T1 &x, const T2 &y) {
    return x < y ? x = y, 1 : 0;
}
template <typename T1, typename T2>
bool chmin(T1 &x, const T2 &y) {
    return x > y ? x = y, 1 : 0;
}

// struct UnionFind {
//     explicit UnionFind(int n) : _n(n), par_or_sz(n, -1) {}

//     int merge(int a, int b) {
//         assert(IN(a, 0, _n) && IN(b, 0, _n));
//         int x = find(a), y = find(b);
//         if (x == y) return x;
//         if (-par_or_sz[x] < -par_or_sz[y]) swap(x, y);
//         par_or_sz[x] += par_or_sz[y];
//         return par_or_sz[y] = x;
//     }

//     int find(int a) {
//         assert(IN(a, 0, _n));
//         return par_or_sz[a] < 0 ? a : par_or_sz[a] = find(par_or_sz[a]);
//     }

//     bool same(int a, int b) {
//         assert(IN(a, 0, _n) && IN(b, 0, _n));
//         return find(a) == find(b);
//     }

//    protected:
//     int _n;
//     vl par_or_sz;
// };

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<pair<int, int>> XYs(N);
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        XYs[i] = {x, y};
    }

    vector<tuple<int, int, int>> edges;
    REP(i, N) {
        auto [xi, yi] = XYs[i];
        REP2(j, i + 1, N) {
            auto [xj, yj] = XYs[j];
            edges.eb((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj), i, j);
        }
    }
    sort(ALL(edges));

    set<int> seen;
    vp ans;
    EACH3(w, i, j, edges) {
        if (seen.find(i) == seen.end() && seen.find(j) == seen.end()) {
            ans.eb(i, j);
            seen.insert(i);
            seen.insert(j);
        }
    }

    OUT(ans.size());
    EACH(e, ans) { OUT(e.first + 1, e.second + 1); }

    return 0;
}
0