結果

問題 No.2251 Marking Grid
ユーザー bayashikobayashiko
提出日時 2023-03-07 21:33:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 3,000 ms
コード長 2,830 bytes
コンパイル時間 8,661 ms
コンパイル使用メモリ 287,568 KB
実行使用メモリ 35,788 KB
最終ジャッジ日時 2023-10-18 05:38:31
合計ジャッジ時間 14,391 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 214 ms
35,016 KB
testcase_23 AC 260 ms
35,788 KB
testcase_24 AC 10 ms
5,252 KB
testcase_25 AC 262 ms
35,776 KB
testcase_26 AC 56 ms
12,748 KB
testcase_27 AC 137 ms
32,252 KB
testcase_28 AC 8 ms
4,464 KB
testcase_29 AC 144 ms
32,532 KB
testcase_30 AC 46 ms
12,436 KB
testcase_31 AC 31 ms
7,496 KB
testcase_32 AC 14 ms
5,376 KB
testcase_33 AC 161 ms
32,872 KB
testcase_34 AC 19 ms
7,932 KB
testcase_35 AC 79 ms
18,268 KB
testcase_36 AC 100 ms
18,728 KB
testcase_37 AC 135 ms
32,080 KB
testcase_38 AC 9 ms
4,492 KB
testcase_39 AC 6 ms
4,400 KB
testcase_40 AC 73 ms
18,056 KB
testcase_41 AC 38 ms
10,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
//typedef __int128_t llint;
#include<atcoder/all>
using namespace atcoder;

int main(void){
    int H,W;
    cin >> H >> W;
    lint A[H][W];
    rep(i,H) rep(j,W) cin >> A[i][j];
    /*lint naive_ans=0;
    rep(i,(1<<(H*W))){
        int M[H][W]={};
        lint maxi=0;
        rep(j,H) rep(k,W){
            if(i&(1<<(j*W+k))) M[j][k]=1,chmax(maxi,A[j][k]);
        }
        bool ok=true;
        rep(j,H-1) rep(k,W-1){
            int sum=M[j][k]+M[j+1][k]+M[j][k+1]+M[j+1][k+1];
            if(sum%2) ok=false;
        }
        if(ok) naive_ans+=maxi;
    }
    cout << naive_ans << endl;
    lint ans=0;
    rep(i,(1<<H)) rep(j,(1<<W)){
        bool M[H][W]={};
        rep(k,H){
            if(i&(1<<k)){
                rep(l,W) M[k][l]^=1;
            }
        }
        rep(k,W){
            if(j&(1<<k)){
                rep(l,H) M[l][k]^=1;
            }
        }
        lint maxi=0;
        rep(k,H) rep(l,W) if(M[k][l]) chmax(maxi,A[k][l]);
        ans+=maxi;
    }
    cout << ans/2 << endl;*/
    using mint=modint998244353;
    mint fast_ans=0;
    dsu uf(H+W);
    lint ufcomp=H+W;
    vector<pair<lint,plint>> masu;
    rep(i,H) rep(j,W) masu.push_back({A[i][j],{i,j}});
    sort(all(masu));
    reverse(all(masu));
    for(auto e:masu){
        lint nx=e.se.fi,ny=e.se.se;
        lint num=e.fi;
        if(uf.same(nx,H+ny)) continue;
        uf.merge(nx,H+ny);
        ufcomp--;
        mint add=num;
        add*=pow_mod(2,ufcomp-1,MOD);
        uf.merge(nx,H+ny);
        fast_ans+=add;
    }
    cout << fast_ans.val() << endl;
}
0