結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー coindarwcoindarw
提出日時 2024-02-23 22:49:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,244 bytes
コンパイル時間 6,234 ms
コンパイル使用メモリ 336,468 KB
実行使用メモリ 55,428 KB
最終ジャッジ日時 2024-09-29 08:01:09
合計ジャッジ時間 59,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 474 ms
6,816 KB
testcase_07 WA -
testcase_08 AC 598 ms
23,692 KB
testcase_09 AC 607 ms
26,964 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 699 ms
35,992 KB
testcase_14 AC 804 ms
49,656 KB
testcase_15 AC 668 ms
33,572 KB
testcase_16 AC 606 ms
26,604 KB
testcase_17 WA -
testcase_18 AC 678 ms
32,388 KB
testcase_19 WA -
testcase_20 AC 842 ms
49,412 KB
testcase_21 AC 801 ms
51,120 KB
testcase_22 AC 851 ms
50,052 KB
testcase_23 AC 842 ms
50,772 KB
testcase_24 AC 809 ms
50,880 KB
testcase_25 AC 840 ms
50,392 KB
testcase_26 AC 802 ms
51,380 KB
testcase_27 AC 854 ms
49,876 KB
testcase_28 AC 798 ms
50,168 KB
testcase_29 AC 863 ms
50,024 KB
testcase_30 AC 860 ms
49,596 KB
testcase_31 AC 858 ms
50,888 KB
testcase_32 AC 816 ms
52,448 KB
testcase_33 AC 847 ms
48,848 KB
testcase_34 AC 879 ms
50,768 KB
testcase_35 AC 845 ms
49,872 KB
testcase_36 AC 876 ms
49,612 KB
testcase_37 AC 898 ms
50,256 KB
testcase_38 AC 879 ms
49,616 KB
testcase_39 AC 862 ms
48,852 KB
testcase_40 AC 411 ms
55,428 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>

#include <atcoder/all>
#else
#include <mylibs/all.h>
#endif

using ll = long long;
using lll = __int128_t;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define length(v) ((int)(v).size())
constexpr int inf = 2'000'000'000;
constexpr ll linf = 4'000'000'000'000'000'000, M7 = 1'000'000'007, M9 = 998'244'353;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;

// clang-format off
#define Vec(type, ...) __make_vec<type>(__VA_ARGS__)
template <class T> vector<T> __make_vec(size_t a) {return vector<T>(a);}template <class T, class... Ts>
auto __make_vec(size_t a, Ts... ts) {return vector<decltype(__make_vec<T>(ts...))>(a, __make_vec<T>(ts...));}
#define VecI(init, type, ...) __make_vecI<type, init>(__VA_ARGS__)
template <class T, T init>vector<T> __make_vecI(size_t a) {return vector<T>(a, init);}
template <class T, T init, class... Ts>
auto __make_vecI(size_t a, Ts... ts) {return vector<decltype(__make_vecI<T, init>(ts...))>(a, __make_vecI<T, init>(ts...));}

template <typename T, typename U>inline ostream& operator<<(ostream& os, const pair<T, U>& p) noexcept {return os << p.first << " " << p.second;}
inline ostream& operator<<(ostream& os, const modint& m) noexcept { return os << m.val(); }
template <int M>inline ostream& operator<<(ostream& os, const static_modint<M>& m) noexcept { return os << m.val(); }

template <typename T> struct is_static_modint : std::false_type {}; template <int MOD> struct is_static_modint<static_modint<MOD>> : std::true_type {};
template <template <typename...> typename C, typename Number>concept MyContainer = std::is_same_v<C<Number>, std::vector<Number>> || std::is_same_v<C<Number>, std::deque<Number>> || std::is_same_v<C<Number>, std::set<Number>> || std::is_same_v<C<Number>, std::unordered_set<Number>> || std::is_same_v<C<Number>, std::unordered_multiset<Number>> || std::is_same_v<C<Number>, std::multiset<Number>>;
template <typename Number>concept MyNumber = std::is_same_v<Number, int> || std::is_same_v<Number, ll> || std::is_same_v<Number, char> || std::is_same_v<Number, modint> || is_static_modint<Number>::value;
template <template <typename...> typename C, typename Number>concept MyContainerNumber = MyContainer<C, Number> && MyNumber<Number>;
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>concept MyNestedContainerNumber = MyContainer<OutCon, InCon<Number>> && MyContainerNumber<InCon, Number>;
template <template <typename...> typename C, typename Number>requires MyContainerNumber<C, Number>std::ostream& operator<<(std::ostream& os, const C<Number>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << ' ' << *itr;}return os;}
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>requires MyNestedContainerNumber<OutCon, InCon, Number>std::ostream& operator<<(std::ostream& os, const OutCon<InCon<Number>>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << '\n' << *itr;}return os;}
template <typename T, typename U>istream& operator>>(istream& is, pair<T, U>& p) {return is >> p.first >> p.second;}
template <typename T>istream& operator>>(istream& is, vector<T>& v) {for (auto& e : v) is >> e;return is;}
void inp() {}
template <typename T, typename... Args>void inp(T& a, Args&... args) {cin >> a, inp(args...);}
template <typename T>void inp1(vector<T>& v, int offset = 1, int len = -1) {if (len == -1) len = int(v.size()) - offset;assert(offset >= 0 && len >= 0);for (int i = offset; i < offset + len; ++i) cin >> v[i];}
template <typename T>void oup(const T& a) {cout << a << "\n";}
template <typename T, typename... Args>void oup(const T& a, const Args&... args) {cout << a << " ", oup(args...);}

inline string YESNO(bool cond) { return cond ? "YES" : "NO"; }inline string yesno(bool cond) { return cond ? "yes" : "no"; }inline string YesNo(bool cond) { return cond ? "Yes" : "No"; }
inline auto add1(auto vec, ll offset = 1) {for (auto& e : vec) e += offset;return vec;}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>void debug_out(T t) {cerr << t << "\n";}
template <typename T, typename... Args>void debug_out(T t, Args... args) {cerr << t << ", ";debug_out(args...);}
#endif

#ifdef ONLINE_JUDGE
#define todo(...) static_assert(false)
#else
#define todo(...)
#endif
// clang-format on

// https://hitonanode.github.io/cplib-cpp/graph/manhattan_mst.hpp.html

template <typename T>
std::vector<std::tuple<T, int, int>> manhattan_mst(std::vector<T> xs, std::vector<T> ys) {
    const int n = xs.size();
    std::vector<int> idx(n);
    std::iota(idx.begin(), idx.end(), 0);
    std::vector<std::tuple<T, int, int>> ret;
    for (int s = 0; s < 2; s++) {
        for (int t = 0; t < 2; t++) {
            auto cmp = [&](int i, int j) { return xs[i] + ys[i] < xs[j] + ys[j]; };
            std::sort(idx.begin(), idx.end(), cmp);
            std::map<T, int> sweep;
            for (int i : idx) {
                for (auto it = sweep.lower_bound(-ys[i]); it != sweep.end(); it = sweep.erase(it)) {
                    int j = it->second;
                    if (xs[i] - xs[j] < ys[i] - ys[j]) break;
                    ret.emplace_back(std::abs(xs[i] - xs[j]) + std::abs(ys[i] - ys[j]), i, j);
                }
                sweep[-ys[i]] = i;
            }
            std::swap(xs, ys);
        }
        for (auto& x : xs) x = -x;
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int Q;
    inp(Q);
    while (Q--) {
        ll n, l;
        inp(n, l);
        using P = pair<ll, ll>;
        vector<P> vp(n);
        inp(vp);
        vector<int> vx(n), vy(n);
        rep(i, n) {
            vx[i] = vp[i].first;
            vy[i] = vp[i].second;
        }
        auto ret = manhattan_mst(vx, vy);
        dsu ds(n);
        struct edge {
            int to;
            edge(int to) : to(to) {}
        };
        vector<vector<edge>> G(n);
        for (auto [w, i, j] : ret) {
            if (ds.merge(i, j)) {
                G[i].emplace_back(j);
                G[j].emplace_back(i);
            }
        }
        vector<int> ans;
        vector<bool> seen(n);
        auto dfs = [&](auto dfs, int u) -> void {
            seen.at(u) = true;
            ans.push_back(u);
            for (const auto& e : G.at(u)) {
                if (seen.at(e.to)) continue;
                dfs(dfs, e.to);
            }
            ans.push_back(u);
        };

        dfs(dfs, 0);
        ans.pop_back();
        oup(ans.size());
        for (auto e : ans) {
            oup(vp[e]);
        }
    }
    return 0;
}
0