結果
問題 |
No.1166 NADA DNA
|
ユーザー |
|
提出日時 | 2020-08-18 06:50:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,494 bytes |
コンパイル時間 | 2,317 ms |
コンパイル使用メモリ | 101,508 KB |
最終ジャッジ日時 | 2025-01-13 02:50:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:56:15: error: 'std::tuple<int, int, int> <structured bindings>' has incomplete type 56 | for (auto [c, u, v] : es) { | ^~~~~~~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/move.h:57, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/exception_ptr.h:43, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/exception:168, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/ios:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/iostream:39, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/type_traits: In substitution of 'template<class _Tp, class ... _Args> using __is_nothrow_constructible_impl = std::__bool_constant<__is_nothrow_constructible(_Tp)> [with _Tp = std::tuple<int, int, int>; _Args = {int&, int&, int&}]': /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/type_traits:1047:12: required from 'struct std::is_nothrow_constructible<std::tuple<int, int, int>, int&, int&, int&>' /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/alloc_traits.h:513:57: required from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>; allocator_type = std::allocator<std::tuple<int, int, int> >]' /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/vector.tcc:117:30: required from 'constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::
ソースコード
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> struct UnionFind { std::vector<int> par, sz; int gnum; explicit UnionFind(int n) : par(n), sz(n, 1), gnum(n) { std::iota(par.begin(), par.end(), 0); } int find(int v) { return (par[v] == v) ? v : (par[v] = find(par[v])); } void unite(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (sz[u] < sz[v]) std::swap(u, v); sz[u] += sz[v]; par[v] = u; --gnum; } bool same(int u, int v) { return find(u) == find(v); } bool ispar(int v) { return v == find(v); } int size(int v) { return sz[find(v)]; } }; void solve() { int n, m; std::cin >> n >> m; std::vector<std::string> ss(n); for (auto& s : ss) std::cin >> s; std::vector<std::tuple<int, int, int>> es; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { int c = 0; for (int k = 0; k < m; ++k) { if (ss[i][k] != ss[j][k]) ++c; } es.emplace_back(c, i, j); } } std::sort(es.begin(), es.end()); int ans = 0; UnionFind uf(n); for (auto [c, u, v] : es) { if (uf.same(u, v)) continue; ans += c; uf.unite(u, v); } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }