結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 389 ms
15,100 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 WA -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 WA -
testcase_39 RE -
testcase_40 WA -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

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+W))
		{
			ans+=tmp*inv2*p.first;
			uf.merge(i,j+W);
			tmp*=inv2;
		}
	}
	cout<<ans.val()<<endl;
}
0