結果

問題 No.2251 Marking Grid
ユーザー titiatitia
提出日時 2023-03-22 05:54:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,990 ms / 3,000 ms
コード長 981 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 11,960 KB
実行使用メモリ 147,716 KB
最終ジャッジ日時 2023-10-18 18:49:38
合計ジャッジ時間 23,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,316 KB
testcase_01 AC 30 ms
10,316 KB
testcase_02 AC 30 ms
10,316 KB
testcase_03 AC 31 ms
10,316 KB
testcase_04 AC 31 ms
10,316 KB
testcase_05 AC 31 ms
10,316 KB
testcase_06 AC 30 ms
10,316 KB
testcase_07 AC 31 ms
10,316 KB
testcase_08 AC 32 ms
10,316 KB
testcase_09 AC 31 ms
10,316 KB
testcase_10 AC 30 ms
10,316 KB
testcase_11 AC 31 ms
10,316 KB
testcase_12 AC 31 ms
10,316 KB
testcase_13 AC 31 ms
10,328 KB
testcase_14 AC 31 ms
10,320 KB
testcase_15 AC 31 ms
10,320 KB
testcase_16 AC 31 ms
10,320 KB
testcase_17 AC 31 ms
10,320 KB
testcase_18 AC 31 ms
10,316 KB
testcase_19 AC 30 ms
10,316 KB
testcase_20 AC 31 ms
10,316 KB
testcase_21 AC 31 ms
10,316 KB
testcase_22 AC 2,478 ms
125,604 KB
testcase_23 AC 2,990 ms
147,716 KB
testcase_24 AC 99 ms
14,888 KB
testcase_25 AC 2,956 ms
147,440 KB
testcase_26 AC 611 ms
36,340 KB
testcase_27 AC 1,552 ms
85,516 KB
testcase_28 AC 79 ms
13,784 KB
testcase_29 AC 1,706 ms
89,968 KB
testcase_30 AC 520 ms
34,156 KB
testcase_31 AC 371 ms
27,384 KB
testcase_32 AC 133 ms
17,052 KB
testcase_33 AC 1,830 ms
94,276 KB
testcase_34 AC 173 ms
17,860 KB
testcase_35 AC 857 ms
53,160 KB
testcase_36 AC 1,107 ms
64,804 KB
testcase_37 AC 1,511 ms
80,756 KB
testcase_38 AC 85 ms
13,636 KB
testcase_39 AC 61 ms
12,716 KB
testcase_40 AC 749 ms
43,764 KB
testcase_41 AC 369 ms
29,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]

mod=998244353
POW2=[1]
for i in range(3000):
    POW2.append(POW2[-1]*2%mod)

# UnionFind

Group = [i for i in range(H+W+1)] # グループ分け
Nodes = [1]*(H+W+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

X=[]
for i in range(H):
    for j in range(W):
        X.append((A[i][j],i,j))

X.sort(reverse=True)

ANS=0
now=H+W-2
for a,i,j in X:
    if find(i)==find(j+H):
        continue
    else:
        ANS=(ANS+a*POW2[now])%mod
        now-=1
        Union(i,j+H)

print(ANS)
0