結果
問題 | No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ |
ユーザー | t98slider |
提出日時 | 2024-03-05 00:19:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 493 ms / 2,000 ms |
コード長 | 3,949 bytes |
コンパイル時間 | 2,734 ms |
コンパイル使用メモリ | 233,700 KB |
実行使用メモリ | 50,780 KB |
最終ジャッジ日時 | 2024-09-29 17:43:46 |
合計ジャッジ時間 | 39,699 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 294 ms
6,816 KB |
testcase_02 | AC | 289 ms
6,816 KB |
testcase_03 | AC | 295 ms
6,816 KB |
testcase_04 | AC | 334 ms
6,816 KB |
testcase_05 | AC | 335 ms
6,816 KB |
testcase_06 | AC | 358 ms
6,820 KB |
testcase_07 | AC | 392 ms
16,224 KB |
testcase_08 | AC | 414 ms
14,816 KB |
testcase_09 | AC | 454 ms
17,596 KB |
testcase_10 | AC | 399 ms
17,788 KB |
testcase_11 | AC | 393 ms
15,544 KB |
testcase_12 | AC | 395 ms
16,236 KB |
testcase_13 | AC | 434 ms
23,904 KB |
testcase_14 | AC | 469 ms
29,184 KB |
testcase_15 | AC | 425 ms
20,196 KB |
testcase_16 | AC | 398 ms
16,372 KB |
testcase_17 | AC | 416 ms
18,280 KB |
testcase_18 | AC | 432 ms
19,500 KB |
testcase_19 | AC | 422 ms
21,824 KB |
testcase_20 | AC | 493 ms
30,252 KB |
testcase_21 | AC | 488 ms
29,992 KB |
testcase_22 | AC | 479 ms
29,992 KB |
testcase_23 | AC | 475 ms
30,120 KB |
testcase_24 | AC | 481 ms
29,988 KB |
testcase_25 | AC | 479 ms
30,252 KB |
testcase_26 | AC | 479 ms
29,872 KB |
testcase_27 | AC | 491 ms
30,120 KB |
testcase_28 | AC | 483 ms
29,996 KB |
testcase_29 | AC | 479 ms
29,988 KB |
testcase_30 | AC | 492 ms
30,120 KB |
testcase_31 | AC | 479 ms
30,116 KB |
testcase_32 | AC | 474 ms
29,844 KB |
testcase_33 | AC | 476 ms
30,120 KB |
testcase_34 | AC | 475 ms
30,248 KB |
testcase_35 | AC | 488 ms
30,120 KB |
testcase_36 | AC | 483 ms
29,860 KB |
testcase_37 | AC | 473 ms
29,996 KB |
testcase_38 | AC | 478 ms
29,860 KB |
testcase_39 | AC | 482 ms
30,124 KB |
testcase_40 | AC | 278 ms
50,780 KB |
testcase_41 | AC | 321 ms
41,740 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct dsu { public: int csz; dsu() : _n(0) {} dsu(int n) : _n(n), csz(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); csz--; parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; vector<tuple<int,int,int>> manhattan_mst(vector<int> xs, vector<int> ys) { assert(xs.size() == ys.size()); vector<tuple<int,int,int>> ret; int n = (int) xs.size(); vector< int > ord(n); iota(ord.begin(), ord.end(), 0); for(int s = 0; s < 2; s++) { for(int t = 0; t < 2; t++) { auto cmp = [&](int i, int j) -> bool { return xs[i] + ys[i] < xs[j] + ys[j]; }; sort(ord.begin(), ord.end(), cmp); map< int, int > idx; for(int i:ord) { for(auto it = idx.lower_bound(-ys[i]); it != idx.end(); it = idx.erase(it)) { int j = it->second; if(xs[i] - xs[j] < ys[i] - ys[j]) break; ret.emplace_back(i, j, abs(xs[i] - xs[j]) + abs(ys[i] - ys[j])); } idx[-ys[i]] = i; } swap(xs, ys); } for(int i = 0; i < n; i++) xs[i] *= -1; } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ int N, L; cin >> N >> L; vector<int> x(N), y(N); for(int i = 0; i < N; i++){ cin >> x[i] >> y[i]; } dsu uf(N); auto edge = manhattan_mst(x, y); sort(edge.begin(), edge.end(), [&](tuple<int,int,int> lhs, tuple<int,int,int> rhs){ return get<2>(lhs) < get<2>(rhs); }); vector<vector<int>> g(N); for(auto [u, v, c] : edge){ if(uf.same(u, v)) continue; uf.merge(u, v); g[u].push_back(v); g[v].push_back(u); } vector<pair<int,int>> ans; auto dfs = [&](auto dfs, int v, int p) -> void { ans.emplace_back(x[v], y[v]); for(auto u : g[v]){ if(u == p) continue; dfs(dfs, u, v); } }; dfs(dfs, 0, -1); ll d = 0; for(int i = 0; i + 1 < N; i++){ d += abs(ans[i].first - ans[i + 1].first) + abs(ans[i].second - ans[i + 1].second); } cout << N << '\n'; for(auto [x, y] : ans) cout << x << ' ' << y << '\n'; } }