結果

問題 No.2251 Marking Grid
ユーザー momoyuumomoyuu
提出日時 2023-10-25 00:04:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 472 ms / 3,000 ms
コード長 1,275 bytes
コンパイル時間 4,074 ms
コンパイル使用メモリ 278,304 KB
実行使用メモリ 30,816 KB
最終ジャッジ日時 2023-10-25 00:04:35
合計ジャッジ時間 9,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 404 ms
28,016 KB
testcase_23 AC 470 ms
30,816 KB
testcase_24 AC 57 ms
4,508 KB
testcase_25 AC 472 ms
30,800 KB
testcase_26 AC 82 ms
9,660 KB
testcase_27 AC 292 ms
24,488 KB
testcase_28 AC 136 ms
4,372 KB
testcase_29 AC 281 ms
24,648 KB
testcase_30 AC 89 ms
9,588 KB
testcase_31 AC 105 ms
6,808 KB
testcase_32 AC 91 ms
4,628 KB
testcase_33 AC 272 ms
24,988 KB
testcase_34 AC 29 ms
5,816 KB
testcase_35 AC 238 ms
14,424 KB
testcase_36 AC 247 ms
14,952 KB
testcase_37 AC 242 ms
24,196 KB
testcase_38 AC 12 ms
4,372 KB
testcase_39 AC 106 ms
4,372 KB
testcase_40 AC 109 ms
14,108 KB
testcase_41 AC 161 ms
9,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


#include<atcoder/modint>
using mint = atcoder::modint998244353;
using B = bitset<1000>;
#include<atcoder/dsu>
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
   
    int h,w;
    cin>>h>>w;
    vector<vector<ll>> a(h,vector<ll>(w,0));
    for(int i = 0;i<h;i++) for(int j = 0;j<w;j++) cin>>a[i][j];
    vector<pair<ll,pair<int,int>>> use;
    for(int i = 0;i<h;i++) for(int j = 0;j<w;j++) use.push_back(make_pair(a[i][j],make_pair(i,j)));
    sort(use.rbegin(),use.rend());
    mint ans = 0;
    mint now = mint(2).pow(h+w-1);
    int cnt = h + w - 1;

    vector<vector<int>> ok(h,vector<int>(w,0));
    vector<B> c(w);
    atcoder::dsu uf(w);
    for(int i = 0;i<use.size();i++){
        int ni = use[i].second.first;
        int nj = use[i].second.second;
        if(c[nj][ni]) continue;
        int nxt = cnt - 1;
        ans += mint(a[ni][nj]) * (mint(2).pow(cnt)-mint(2).pow(nxt));
        cnt--;
        c[nj].set(ni);
        for(int j = 0;j<w;j++) if((c[nj]&c[j]).count()>0) uf.merge(nj,j);
        for(auto&now:uf.groups()){
            B use;
            for(auto&j:now) use |= c[j];
            for(auto&j:now) c[j] = use;
        }
    }
    cout<<ans.val()<<endl;

    
}
0