結果

問題 No.2251 Marking Grid
ユーザー shobonvipshobonvip
提出日時 2023-03-17 23:16:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,496 ms / 3,000 ms
コード長 1,277 bytes
コンパイル時間 6,812 ms
コンパイル使用メモリ 274,944 KB
実行使用メモリ 62,200 KB
最終ジャッジ日時 2023-10-18 16:18:07
合計ジャッジ時間 16,611 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_11 AC 1 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 1,216 ms
53,008 KB
testcase_23 AC 1,496 ms
62,200 KB
testcase_24 AC 30 ms
5,468 KB
testcase_25 AC 1,487 ms
61,928 KB
testcase_26 AC 233 ms
16,944 KB
testcase_27 AC 719 ms
35,796 KB
testcase_28 AC 21 ms
4,996 KB
testcase_29 AC 794 ms
39,704 KB
testcase_30 AC 198 ms
14,396 KB
testcase_31 AC 122 ms
10,996 KB
testcase_32 AC 48 ms
6,236 KB
testcase_33 AC 1,028 ms
42,000 KB
testcase_34 AC 63 ms
7,328 KB
testcase_35 AC 445 ms
21,716 KB
testcase_36 AC 602 ms
26,404 KB
testcase_37 AC 829 ms
34,792 KB
testcase_38 AC 25 ms
5,228 KB
testcase_39 AC 17 ms
4,584 KB
testcase_40 AC 385 ms
20,176 KB
testcase_41 AC 167 ms
11,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int h,w;cin>>h>>w;
	vector<vector<int>> a(h, vector<int>(w));
	vector<ll> v(0);
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			cin >> a[i][j];
			v.push_back(((ll)a[i][j] << (ll)30) + (i<<15) + j);
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ll mask = (1<<15) - 1;
	vector<int> x(h);
	dsu uf(w);
	int cnt = w;
	int cnth = h;
	vector<set<int>> hr(h);
	mint ans = 0;
	for (ll ty: v){
		int j = ty & mask;
		int i = (ty>>15) & mask;
		mint val = ty >> 30;
		int tv = cnt + cnth - 2;
		int mode = 1;
		auto g = hr[i].lower_bound(j);
		if (g != hr[i].end()){
			int k = *g;
			if (uf.same(k,j)) mode = 0;
		}
		if (g != hr[i].begin()){
			g--;
			int k = *g;
			if (uf.same(k,j)) mode = 0;
		}
		if (mode == 1){
			ans += mint(2).pow(tv) * val;
		}
		if (x[i] == 0){
			x[i] = 1;
			cnth -= 1;
		}
		g = hr[i].lower_bound(j);
		if (g != hr[i].end()){
			int k = *g;
			if (!uf.same(k,j)){
				uf.merge(k,j);
				cnt-=1;
			}
		}
		if (g != hr[i].begin()){
			g--;
			int k = *g;
			if (!uf.same(k,j)){
				uf.merge(k,j);
				cnt-=1;
			}
		}
		hr[i].insert(j);
	}
	cout << ans.val() <<endl;
}
0