結果

問題 No.2251 Marking Grid
ユーザー 沙耶花沙耶花
提出日時 2023-03-17 21:57:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 399 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 6,623 ms
コンパイル使用メモリ 269,164 KB
実行使用メモリ 15,992 KB
最終ジャッジ日時 2023-10-18 14:35:04
合計ジャッジ時間 10,000 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_10 AC 2 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 339 ms
15,512 KB
testcase_23 AC 396 ms
15,992 KB
testcase_24 AC 14 ms
4,348 KB
testcase_25 AC 399 ms
15,984 KB
testcase_26 AC 92 ms
6,396 KB
testcase_27 AC 219 ms
14,336 KB
testcase_28 AC 12 ms
4,348 KB
testcase_29 AC 234 ms
14,352 KB
testcase_30 AC 75 ms
6,224 KB
testcase_31 AC 51 ms
4,928 KB
testcase_32 AC 28 ms
4,348 KB
testcase_33 AC 368 ms
14,536 KB
testcase_34 AC 38 ms
4,692 KB
testcase_35 AC 177 ms
9,508 KB
testcase_36 AC 226 ms
9,576 KB
testcase_37 AC 307 ms
14,124 KB
testcase_38 AC 17 ms
4,348 KB
testcase_39 AC 11 ms
4,348 KB
testcase_40 AC 163 ms
9,156 KB
testcase_41 AC 80 ms
6,024 KB
権限があれば一括ダウンロードができます

ソースコード

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