結果

問題 No.2251 Marking Grid
ユーザー titiatitia
提出日時 2023-03-22 05:53:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 923 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 237,644 KB
最終ジャッジ日時 2023-10-18 18:49:11
合計ジャッジ時間 10,950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,440 KB
testcase_01 AC 37 ms
53,440 KB
testcase_02 AC 37 ms
53,440 KB
testcase_03 AC 37 ms
53,440 KB
testcase_04 AC 37 ms
53,440 KB
testcase_05 AC 37 ms
53,440 KB
testcase_06 AC 37 ms
53,440 KB
testcase_07 AC 38 ms
53,440 KB
testcase_08 AC 37 ms
53,440 KB
testcase_09 AC 37 ms
53,440 KB
testcase_10 AC 38 ms
53,440 KB
testcase_11 AC 37 ms
53,440 KB
testcase_12 AC 37 ms
53,440 KB
testcase_13 AC 37 ms
53,440 KB
testcase_14 AC 37 ms
53,440 KB
testcase_15 AC 37 ms
53,440 KB
testcase_16 AC 37 ms
53,440 KB
testcase_17 AC 38 ms
53,440 KB
testcase_18 AC 38 ms
53,440 KB
testcase_19 AC 38 ms
53,440 KB
testcase_20 AC 38 ms
53,440 KB
testcase_21 AC 37 ms
53,440 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 140 ms
81,240 KB
testcase_25 TLE -
testcase_26 AC 862 ms
109,864 KB
testcase_27 AC 2,037 ms
160,648 KB
testcase_28 AC 119 ms
79,664 KB
testcase_29 AC 2,211 ms
160,628 KB
testcase_30 AC 646 ms
111,952 KB
testcase_31 AC 485 ms
95,940 KB
testcase_32 AC 190 ms
83,200 KB
testcase_33 AC 2,628 ms
168,624 KB
testcase_34 AC 234 ms
87,728 KB
testcase_35 AC 1,224 ms
126,344 KB
testcase_36 AC 1,545 ms
134,244 KB
testcase_37 AC 2,059 ms
155,208 KB
testcase_38 AC 130 ms
80,352 KB
testcase_39 AC 95 ms
77,752 KB
testcase_40 AC 1,078 ms
120,552 KB
testcase_41 AC 487 ms
101,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod=998244353

# 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*pow(2,now,mod))%mod
        now-=1
        Union(i,j+H)

print(ANS)
0