結果

問題 No.1166 NADA DNA
ユーザー kotatsugamekotatsugame
提出日時 2020-11-27 06:49:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 3,000 ms
コード長 1,098 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 11,304 KB
最終ジャッジ日時 2023-10-01 03:55:57
合計ジャッジ時間 4,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 28 ms
4,804 KB
testcase_04 AC 111 ms
10,224 KB
testcase_05 AC 110 ms
9,724 KB
testcase_06 AC 110 ms
11,304 KB
testcase_07 AC 110 ms
9,736 KB
testcase_08 AC 110 ms
10,484 KB
testcase_09 AC 111 ms
10,256 KB
testcase_10 AC 111 ms
9,872 KB
testcase_11 AC 110 ms
9,404 KB
testcase_12 AC 111 ms
10,152 KB
testcase_13 AC 111 ms
10,144 KB
testcase_14 AC 109 ms
9,892 KB
testcase_15 AC 110 ms
10,720 KB
testcase_16 AC 111 ms
10,016 KB
testcase_17 AC 110 ms
9,672 KB
testcase_18 AC 110 ms
10,976 KB
testcase_19 AC 110 ms
9,624 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#line 2 "/home/kotatsugame/library/datastructure/UF.cpp"
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
#line 6 "a.cpp"
int N,L;
string S[1000];
main()
{
	cin>>N>>L;
	for(int i=0;i<N;i++)cin>>S[i];
	vector<pair<int,pair<int,int> > >E;
	for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
	{
		int c=0;
		for(int k=0;k<L;k++)c+=S[i][k]!=S[j][k];
		E.push_back(make_pair(c,make_pair(i,j)));
	}
	sort(E.begin(),E.end());
	int ans=0;
	UF uf(N);
	for(pair<int,pair<int,int> >e:E)
	{
		if(uf.unite(e.second.first,e.second.second))ans+=e.first;
	}
	cout<<ans<<endl;
}
0