結果

問題 No.2251 Marking Grid
ユーザー shobonvipshobonvip
提出日時 2023-03-17 23:45:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 418 ms / 3,000 ms
コード長 890 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 177,752 KB
最終ジャッジ日時 2023-10-18 16:37:44
合計ジャッジ時間 7,619 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,408 KB
testcase_01 AC 38 ms
53,408 KB
testcase_02 AC 38 ms
53,408 KB
testcase_03 AC 36 ms
53,408 KB
testcase_04 AC 37 ms
53,408 KB
testcase_05 AC 37 ms
53,408 KB
testcase_06 AC 37 ms
53,408 KB
testcase_07 AC 37 ms
53,408 KB
testcase_08 AC 36 ms
53,408 KB
testcase_09 AC 37 ms
53,408 KB
testcase_10 AC 36 ms
53,408 KB
testcase_11 AC 39 ms
53,408 KB
testcase_12 AC 38 ms
53,408 KB
testcase_13 AC 36 ms
53,408 KB
testcase_14 AC 36 ms
53,408 KB
testcase_15 AC 38 ms
53,408 KB
testcase_16 AC 37 ms
53,408 KB
testcase_17 AC 37 ms
53,408 KB
testcase_18 AC 37 ms
53,408 KB
testcase_19 AC 38 ms
53,408 KB
testcase_20 AC 37 ms
53,408 KB
testcase_21 AC 37 ms
53,408 KB
testcase_22 AC 361 ms
155,068 KB
testcase_23 AC 414 ms
177,752 KB
testcase_24 AC 64 ms
74,308 KB
testcase_25 AC 418 ms
177,748 KB
testcase_26 AC 153 ms
96,464 KB
testcase_27 AC 259 ms
130,428 KB
testcase_28 AC 66 ms
73,944 KB
testcase_29 AC 271 ms
131,796 KB
testcase_30 AC 127 ms
92,800 KB
testcase_31 AC 104 ms
86,020 KB
testcase_32 AC 76 ms
78,816 KB
testcase_33 AC 315 ms
136,688 KB
testcase_34 AC 86 ms
81,052 KB
testcase_35 AC 188 ms
105,276 KB
testcase_36 AC 221 ms
114,644 KB
testcase_37 AC 273 ms
125,596 KB
testcase_38 AC 69 ms
73,944 KB
testcase_39 AC 64 ms
72,812 KB
testcase_40 AC 182 ms
102,068 KB
testcase_41 AC 114 ms
87,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n
	
	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			x, y = y, x
		self.parents[x] += self.parents[y]
		self.parents[y] = x

mod = 998244353
h,w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
v = []
for i in range(h):
	for j in range(w):
		v.append((a[i][j] << 30) + (i << 15) + j)
v.sort()

mask = (1 << 15) - 1
uf = UnionFind(w + h)
cnt = w + h - 2
ans = 0

for ty in v[::-1]:
	j = ty & mask
	i = (ty >> 15) & mask
	val = ty >> 30
	if uf.find(j) == uf.find(i+w): continue
	uf.union(j,i+w)
	ans += pow(2, cnt, mod) * val
	ans %= mod
	cnt -= 1

print(ans)
0