結果

問題 No.2251 Marking Grid
ユーザー kotatsugamekotatsugame
提出日時 2023-03-17 21:49:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 387 ms / 3,000 ms
コード長 709 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 15,100 KB
最終ジャッジ日時 2023-10-18 14:23:49
合計ジャッジ時間 5,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 325 ms
13,320 KB
testcase_23 AC 387 ms
15,100 KB
testcase_24 AC 14 ms
4,348 KB
testcase_25 AC 387 ms
15,100 KB
testcase_26 AC 88 ms
5,936 KB
testcase_27 AC 209 ms
9,760 KB
testcase_28 AC 11 ms
4,348 KB
testcase_29 AC 225 ms
10,024 KB
testcase_30 AC 72 ms
5,408 KB
testcase_31 AC 50 ms
4,880 KB
testcase_32 AC 26 ms
4,348 KB
testcase_33 AC 322 ms
10,552 KB
testcase_34 AC 35 ms
4,348 KB
testcase_35 AC 157 ms
6,924 KB
testcase_36 AC 200 ms
7,980 KB
testcase_37 AC 267 ms
9,496 KB
testcase_38 AC 16 ms
4,348 KB
testcase_39 AC 10 ms
4,348 KB
testcase_40 AC 145 ms
6,728 KB
testcase_41 AC 73 ms
4,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
#include<atcoder/dsu>
using namespace std;
using mint=atcoder::modint998244353;
int H,W;
int main()
{
	cin>>H>>W;
	vector<pair<int,pair<int,int> > >A;
	A.reserve(H*W);
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		int a;cin>>a;
		A.push_back(make_pair(a,make_pair(i,j)));
	}
	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());
	atcoder::dsu uf(H+W);
	mint tmp=mint::raw(2).pow(H+W-1);
	const mint inv2=mint(1)/2;
	mint ans=0;
	for(pair<int,pair<int,int> >p:A)
	{
		int i=p.second.first,j=p.second.second;
		if(!uf.same(i,j+H))
		{
			ans+=tmp*inv2*p.first;
			uf.merge(i,j+H);
			tmp*=inv2;
		}
	}
	cout<<ans.val()<<endl;
}
0