結果

問題 No.2251 Marking Grid
ユーザー publfl2publfl2
提出日時 2023-03-17 22:47:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 3,000 ms
コード長 1,461 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 58,176 KB
実行使用メモリ 23,764 KB
最終ジャッジ日時 2023-10-18 15:49:29
合計ジャッジ時間 4,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 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 1 ms
4,348 KB
testcase_22 AC 194 ms
23,344 KB
testcase_23 AC 231 ms
23,764 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 231 ms
23,756 KB
testcase_26 AC 56 ms
11,672 KB
testcase_27 AC 130 ms
22,524 KB
testcase_28 AC 8 ms
4,348 KB
testcase_29 AC 138 ms
22,720 KB
testcase_30 AC 47 ms
10,436 KB
testcase_31 AC 32 ms
7,616 KB
testcase_32 AC 16 ms
4,348 KB
testcase_33 AC 181 ms
23,756 KB
testcase_34 AC 21 ms
7,616 KB
testcase_35 AC 89 ms
14,328 KB
testcase_36 AC 111 ms
14,328 KB
testcase_37 AC 152 ms
22,944 KB
testcase_38 AC 10 ms
6,176 KB
testcase_39 AC 6 ms
4,348 KB
testcase_40 AC 82 ms
15,560 KB
testcase_41 AC 41 ms
8,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#define MOD 998244353

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=MOD;
		b/=2;
		k*=k, k%=MOD;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}

int next[100010];
int find(int k)
{
	if(k==next[k]) return k;
	else return next[k] = find(next[k]);
}

struct str{
	int first;
	int second;
	long long int value;
};
std::vector<str> event;
bool cmp(str a, str b)
{
	return a.value<b.value;
}

int x[1010][1010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) scanf("%d",&x[i][j]);
	
	for(int i=1;i<=2*a+2*b;i++) next[i] = i;
	int C = a + b;
	
	for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) event.push_back({i,j,x[i][j]});
	std::sort(event.begin(),event.end(),cmp);
	long long int ans = 0;
	while(!event.empty())
	{
		int x0 = event.back().first;
		int y0 = event.back().second;
		long long int val = event.back().value;
		event.pop_back();
		int s1 = x0, s2 = a+y0;
		if(find(s1)==find(s2+a+b)) continue;
		else if(find(s1)==find(s2)) ans += (power(2,C)*val)%MOD, ans %= MOD;
		else
		{
			C--;
			ans += (power(2,C)*val)%MOD, ans %= MOD;
			next[find(s1)] = find(s2+a+b);
			next[find(s1+a+b)] = find(s2);
			if(find(s1)==find(s1+a+b)) break;
			if(find(s2)==find(s2+a+b)) break;
		}
	}
	ans *= inv(2), ans %= MOD;
	printf("%lld",ans);
}
0