結果

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

ソースコード

diff #

#include <atcoder/dsu>
#include <atcoder/modint>
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>
using namespace atcoder;
using namespace std;
using mint = modint998244353;


int main(){
    int H, W;
    cin >> H >> W;

    vector<tuple<int, int, int>> A(H * W);
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int a;
            cin >> a;
            A[i * W + j] = {a, i, j + H};
        }
    }
    sort(A.rbegin(), A.rend());

    mint ans = 0,
         pow2 = mint::raw(2).pow(H + W - 1),
         inv2 = mint::raw(2).inv();
    dsu d(H + W);
    for(auto [a, i, j] : A){
        if(d.same(i, j)) continue;
        d.merge(i, j);
        pow2 *= inv2;
        ans += pow2 * a;
    }
    cout << ans.val() << '\n';

    return 0;
}
0