結果
問題 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
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)