結果
問題 | No.2251 Marking Grid |
ユーザー | googol_S0 |
提出日時 | 2023-03-17 21:34:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 583 ms / 3,000 ms |
コード長 | 2,189 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 221,844 KB |
最終ジャッジ日時 | 2024-09-18 10:22:03 |
合計ジャッジ時間 | 7,524 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,608 KB |
testcase_01 | AC | 36 ms
52,608 KB |
testcase_02 | AC | 36 ms
52,864 KB |
testcase_03 | AC | 37 ms
53,120 KB |
testcase_04 | AC | 35 ms
52,608 KB |
testcase_05 | AC | 34 ms
52,736 KB |
testcase_06 | AC | 41 ms
52,480 KB |
testcase_07 | AC | 34 ms
52,992 KB |
testcase_08 | AC | 35 ms
52,608 KB |
testcase_09 | AC | 33 ms
52,864 KB |
testcase_10 | AC | 33 ms
52,400 KB |
testcase_11 | AC | 33 ms
52,480 KB |
testcase_12 | AC | 35 ms
52,864 KB |
testcase_13 | AC | 37 ms
52,480 KB |
testcase_14 | AC | 35 ms
53,120 KB |
testcase_15 | AC | 37 ms
53,248 KB |
testcase_16 | AC | 33 ms
52,864 KB |
testcase_17 | AC | 32 ms
53,120 KB |
testcase_18 | AC | 34 ms
52,736 KB |
testcase_19 | AC | 35 ms
53,248 KB |
testcase_20 | AC | 36 ms
52,864 KB |
testcase_21 | AC | 36 ms
52,608 KB |
testcase_22 | AC | 483 ms
199,592 KB |
testcase_23 | AC | 562 ms
221,844 KB |
testcase_24 | AC | 84 ms
81,920 KB |
testcase_25 | AC | 583 ms
221,508 KB |
testcase_26 | AC | 180 ms
113,152 KB |
testcase_27 | AC | 346 ms
149,628 KB |
testcase_28 | AC | 90 ms
80,128 KB |
testcase_29 | AC | 382 ms
157,452 KB |
testcase_30 | AC | 162 ms
102,548 KB |
testcase_31 | AC | 125 ms
96,256 KB |
testcase_32 | AC | 84 ms
80,768 KB |
testcase_33 | AC | 410 ms
163,776 KB |
testcase_34 | AC | 103 ms
81,920 KB |
testcase_35 | AC | 229 ms
111,768 KB |
testcase_36 | AC | 282 ms
130,980 KB |
testcase_37 | AC | 337 ms
142,772 KB |
testcase_38 | AC | 91 ms
81,408 KB |
testcase_39 | AC | 84 ms
78,848 KB |
testcase_40 | AC | 237 ms
117,888 KB |
testcase_41 | AC | 134 ms
90,240 KB |
ソースコード
class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return False if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return True def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 mod=998244353 H,W=map(int,input().split()) A=[list(map(int,input().split())) for i in range(H)] D=dsu(H+W) P=pow(2,H+W-1,mod) Q=pow(2,mod-2,mod) S=[] for i in range(H): for j in range(W): S.append(A[i][j]*H*W+i*W+j) S.append(0) S.sort(reverse=True) for i in range(H*W+1): S[i]=(S[i]//(H*W),(S[i]//W)%H,S[i]%W) ANS=(P-1)*S[0][0]%mod for i in range(H*W): x,y=S[i][1],S[i][2] z=S[i][0]-S[i+1][0] if D.merge(x,H+y): P=P*Q%mod if P==1: break ANS=(ANS-(P-1)*z)%mod print(ANS%mod)