結果

問題 No.2251 Marking Grid
ユーザー 沙耶花
提出日時 2023-03-17 21:57:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 435 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 4,939 ms
コンパイル使用メモリ 260,128 KB
最終ジャッジ日時 2025-02-11 13:03:16
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001


int main(){
	
	int h,w;
	cin>>h>>w;
	vector a(h,vector<int>(w));
	vector<pair<int,int>> t;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
			t.emplace_back(i,j);
		}
	}
	sort(t.rbegin(),t.rend(),[&](pair<int,int> x,pair<int,int> y){
		return a[x.first][x.second]<a[y.first][y.second];
	});
	int rem = h+w-1;
	mint ans = 0;
	dsu D(h+w);
	rep(i,t.size()){
		int x = t[i].first,y = t[i].second;
		if(D.same(x,h+y))continue;
		D.merge(x,h+y);
		rem--;
		ans += mint(2).pow(rem) * a[x][y];
	}
	cout<<ans.val()<<endl;
	
	return 0;
}
0