結果
問題 | No.2251 Marking Grid |
ユーザー | bayashiko |
提出日時 | 2023-03-07 21:33:31 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 240 ms / 3,000 ms |
コード長 | 2,830 bytes |
コンパイル時間 | 5,361 ms |
コンパイル使用メモリ | 288,608 KB |
実行使用メモリ | 36,728 KB |
最終ジャッジ日時 | 2024-09-18 02:16:22 |
合計ジャッジ時間 | 9,713 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 40 |
ソースコード
#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; }