結果
| 問題 | No.1166 NADA DNA |
| ユーザー |
|
| 提出日時 | 2020-08-18 06:50:42 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,494 bytes |
| 記録 | |
| コンパイル時間 | 359 ms |
| コンパイル使用メモリ | 73,844 KB |
| 最終ジャッジ日時 | 2026-06-12 12:06:51 |
| 合計ジャッジ時間 | 1,782 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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 /usr/include/c++/12/vector:64,
from main.cpp:4:
/usr/include/c++/12/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]’:
/usr/include/c++/12/bits/stl_vector.h:528:7: required from here
/usr/include/c++/12/bits/stl_vector.h:367:49: error: invalid use of incomplete type ‘class std::tuple<int, int, int>’
367 | _M_impl._M_end_of_storage - _M_impl._M_start);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/bits/stl_algobase.h:64,
from /usr/include/c++/12/string:50,
from /usr/include/c++/12/bits/locale_classes.h:40,
from /usr/include/c++/12/bits/ios_base.h:41,
from /usr/include/c++/12/ios:42,
from /usr/include/c++/12/ostream:38,
from /usr/include/c++/12/iostream:39,
from main.cpp:1:
/usr/include/c++/12/bits/stl_pair.h:90:11: note: declaration of ‘class std::tuple<int, int, int>’
90 | class tuple;
| ^~~~~
In file included from /usr/include/c++/12/bits/move.h:57,
from /usr/include/c++/12/bits/exception_ptr.h:43,
from /usr/include/c++/12/exception:168,
from /usr/include/c++/12/ios:39:
/usr/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&}]’:
/usr/include/c++/12/type_traits:1047:12: required from ‘struct std::is
ソースコード
#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;
}