結果

問題 No.2251 Marking Grid
ユーザー momoyuumomoyuu
提出日時 2023-10-24 23:58:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,470 bytes
コンパイル時間 4,389 ms
コンパイル使用メモリ 279,048 KB
実行使用メモリ 32,596 KB
最終ジャッジ日時 2023-10-24 23:59:17
合計ジャッジ時間 9,952 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
32,596 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 1 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 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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


    }
    cout<<ans.val()<<endl;

    
}
0