結果
問題 | No.1285 ゴミ捨て |
ユーザー |
![]() |
提出日時 | 2020-11-14 03:21:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,527 bytes |
コンパイル時間 | 1,811 ms |
コンパイル使用メモリ | 199,964 KB |
最終ジャッジ日時 | 2025-01-16 00:26:47 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 WA * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; class DisjointSet { private: class Node { friend DisjointSet; std::size_t parent; std::size_t size; Node(const std::size_t parent, const std::size_t size) : parent(parent), size(size) {} }; std::vector<Node> nodes; public: explicit DisjointSet(const std::size_t n) : nodes(n, Node(n, 1)) {} std::size_t size() const { return nodes.size(); } std::size_t size(const std::size_t x) { return nodes[root(x)].size; } std::size_t root(const std::size_t x) { if (nodes[x].parent == size()) return x; return nodes[x].parent = root(nodes[x].parent); } bool is_same(const std::size_t x, const std::size_t y) { return root(x) == root(y); } bool unite(const std::size_t x, const std::size_t y) { std::size_t rx = root(x), ry = root(y); if (rx == ry) return false; if (nodes[rx].size < nodes[ry].size) std::swap(rx, ry); nodes[rx].size += nodes[ry].size; nodes[ry].parent = rx; return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(N); for (auto &&e : A) { cin >> e; } sort(A.begin(), A.end()); int res = 0; vector<bool> B(N, false); while (true) { int i = 0; while (i < N && B[i]) { i++; } if (i == N) break; B[i] = true; res++; int j = i + 1; while (j < N) { if (A[i] + 1 < A[j]) { B[j] = true; i = j; } j++; } } cout << res << '\n'; return 0; }