結果

問題 No.1917 LCMST
ユーザー kotatsugamekotatsugame
提出日時 2022-05-07 03:34:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 439 ms / 4,000 ms
コード長 678 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 83,600 KB
実行使用メモリ 37,776 KB
最終ジャッジ日時 2023-09-20 12:09:50
合計ジャッジ時間 16,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 386 ms
20,588 KB
testcase_10 AC 386 ms
19,980 KB
testcase_11 AC 381 ms
20,148 KB
testcase_12 AC 359 ms
19,980 KB
testcase_13 AC 287 ms
11,320 KB
testcase_14 AC 371 ms
20,472 KB
testcase_15 AC 270 ms
7,400 KB
testcase_16 AC 289 ms
11,832 KB
testcase_17 AC 314 ms
20,020 KB
testcase_18 AC 327 ms
20,720 KB
testcase_19 AC 277 ms
7,844 KB
testcase_20 AC 267 ms
5,180 KB
testcase_21 AC 282 ms
7,708 KB
testcase_22 AC 268 ms
5,204 KB
testcase_23 AC 267 ms
5,176 KB
testcase_24 AC 277 ms
7,436 KB
testcase_25 AC 269 ms
5,200 KB
testcase_26 AC 271 ms
5,420 KB
testcase_27 AC 275 ms
9,096 KB
testcase_28 AC 275 ms
7,772 KB
testcase_29 AC 417 ms
36,020 KB
testcase_30 AC 439 ms
37,236 KB
testcase_31 AC 416 ms
37,296 KB
testcase_32 AC 416 ms
37,372 KB
testcase_33 AC 418 ms
37,776 KB
testcase_34 AC 255 ms
4,380 KB
testcase_35 AC 256 ms
4,376 KB
testcase_36 AC 255 ms
4,380 KB
testcase_37 AC 416 ms
36,696 KB
testcase_38 AC 412 ms
37,140 KB
testcase_39 AC 409 ms
36,892 KB
testcase_40 AC 407 ms
37,528 KB
testcase_41 AC 408 ms
37,328 KB
testcase_42 AC 402 ms
36,052 KB
testcase_43 AC 257 ms
4,376 KB
testcase_44 AC 256 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/dsu>
using namespace std;
int N;
bool ex[1<<17];
main()
{
	cin>>N;
	long ans=0;
	for(int i=0;i<N;i++)
	{
		int A;cin>>A;
		if(ex[A])ans+=A;
		else ex[A]=true;
	}
	vector<pair<long,pair<int,int> > >E;
	for(int g=100000;g>=1;g--)
	{
		int prv=-1;
		for(int k=g;k<=100000;k+=g)if(ex[k])
		{
			if(prv!=-1)
			{
				E.push_back(make_pair((long)k*prv/g,make_pair(k,prv)));
			}
			else prv=k;
		}
	}
	sort(E.begin(),E.end());
	atcoder::dsu uf(100001);
	for(pair<long,pair<int,int> >e:E)
	{
		if(!uf.same(e.second.first,e.second.second))
		{
			uf.merge(e.second.first,e.second.second);
			ans+=e.first;
		}
	}
	cout<<ans<<endl;
}
0