結果

問題 No.2838 Diagonals
ユーザー ニックネームニックネーム
提出日時 2024-08-09 22:38:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 79,960 KB
最終ジャッジ日時 2024-08-09 22:38:08
合計ジャッジ時間 3,004 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,352 KB
testcase_01 AC 34 ms
51,968 KB
testcase_02 AC 38 ms
52,992 KB
testcase_03 AC 35 ms
52,608 KB
testcase_04 AC 37 ms
52,224 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 42 ms
54,596 KB
testcase_07 AC 36 ms
52,608 KB
testcase_08 AC 72 ms
73,344 KB
testcase_09 AC 156 ms
79,960 KB
testcase_10 AC 68 ms
73,344 KB
testcase_11 AC 117 ms
79,556 KB
testcase_12 AC 71 ms
75,620 KB
testcase_13 AC 139 ms
78,012 KB
testcase_14 AC 104 ms
76,852 KB
testcase_15 AC 67 ms
74,240 KB
testcase_16 AC 95 ms
76,416 KB
testcase_17 AC 99 ms
76,880 KB
testcase_18 AC 128 ms
77,932 KB
testcase_19 AC 122 ms
77,884 KB
testcase_20 AC 122 ms
77,884 KB
testcase_21 AC 113 ms
77,160 KB
testcase_22 AC 112 ms
77,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UF:
    def __init__(self,n):
        self.p = [-1]*n
    def f(self,x):
        if self.p[x]<0: return x
        else: self.p[x] = self.f(self.p[x]); return self.p[x]
    def u(self,x,y):
        x = self.f(x); y = self.f(y)
        if x==y: return
        if -self.p[x]<-self.p[y]: x,y = y,x
        self.p[x] += self.p[y]; self.p[y] = x
    def s(self,x,y): return self.f(x)==self.f(y)
n,m = map(int,input().split())
s = [input() for _ in range(n)]
x = y = 0; z = 998244353; uf = UF(n*m)
for i in range(n):
    for j in range(m):
        if s[i][j]==".": continue
        x += 1
        if i and j and uf.s(m*(i-1)+j,m*i+(j-1)): y += 1
        if i and s[i-1][j]=="#": uf.u(m*(i-1)+j,m*i+j)
        if j and s[i][j-1]=="#": uf.u(m*i+(j-1),m*i+j)
print(pow(4,x,z)*pow(2,-y,z)%z)
0