結果

問題 No.2251 Marking Grid
ユーザー titiatitia
提出日時 2023-03-22 05:52:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 923 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,004 KB
実行使用メモリ 147,500 KB
最終ジャッジ日時 2023-10-18 18:48:40
合計ジャッジ時間 23,589 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,172 KB
testcase_01 AC 29 ms
10,172 KB
testcase_02 AC 30 ms
10,172 KB
testcase_03 AC 30 ms
10,172 KB
testcase_04 AC 29 ms
10,172 KB
testcase_05 AC 29 ms
10,172 KB
testcase_06 AC 30 ms
10,172 KB
testcase_07 AC 29 ms
10,172 KB
testcase_08 AC 29 ms
10,172 KB
testcase_09 AC 29 ms
10,172 KB
testcase_10 AC 29 ms
10,172 KB
testcase_11 AC 29 ms
10,172 KB
testcase_12 AC 30 ms
10,172 KB
testcase_13 AC 30 ms
10,180 KB
testcase_14 AC 29 ms
10,176 KB
testcase_15 AC 29 ms
10,176 KB
testcase_16 AC 29 ms
10,176 KB
testcase_17 AC 30 ms
10,176 KB
testcase_18 AC 29 ms
10,172 KB
testcase_19 AC 30 ms
10,172 KB
testcase_20 AC 29 ms
10,172 KB
testcase_21 AC 29 ms
10,172 KB
testcase_22 AC 2,544 ms
125,428 KB
testcase_23 TLE -
testcase_24 AC 102 ms
14,764 KB
testcase_25 TLE -
testcase_26 AC 630 ms
36,208 KB
testcase_27 AC 1,659 ms
85,352 KB
testcase_28 AC 80 ms
13,604 KB
testcase_29 AC 1,769 ms
89,644 KB
testcase_30 AC 547 ms
34,028 KB
testcase_31 AC 367 ms
27,400 KB
testcase_32 AC 134 ms
16,832 KB
testcase_33 AC 1,893 ms
94,496 KB
testcase_34 AC 173 ms
17,816 KB
testcase_35 AC 889 ms
53,020 KB
testcase_36 AC 1,153 ms
64,664 KB
testcase_37 AC 1,601 ms
80,628 KB
testcase_38 AC 84 ms
13,420 KB
testcase_39 AC 61 ms
12,552 KB
testcase_40 AC 794 ms
43,652 KB
testcase_41 AC 384 ms
29,636 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