結果

問題 No.2251 Marking Grid
ユーザー cologne
提出日時 2023-03-21 14:29:23
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 400 ms / 3,000 ms
コード長 543 bytes
コンパイル時間 5,486 ms
コンパイル使用メモリ 321,708 KB
実行使用メモリ 15,828 KB
最終ジャッジ日時 2024-09-18 14:22:36
合計ジャッジ時間 10,230 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using Mint = atcoder::modint998244353;
int main()
{
	int N, M;
	cin >> N >> M;
	vector<tuple<int, int, int>> V;
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < M; ++j)
		{
			int t;
			cin >> t;
			V.emplace_back(t, i, j + N);
		}
	sort(V.rbegin(), V.rend());
	atcoder::dsu ufd(M + N);
	int c = N+M - 2;
	Mint ans = 0;
	for (auto [w, i, j] : V)
	{
		if (!ufd.same(i, j))
		{
			ufd.merge(i, j);
			ans += w * (Mint(2).pow(c));
			--c;
		}
	}
	cout << ans.val() << endl;
}
0