結果
| 問題 |
No.1846 Good Binary Matrix
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2021-08-21 17:01:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 657 ms / 2,000 ms |
| コード長 | 986 bytes |
| コンパイル時間 | 273 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 89,088 KB |
| 最終ジャッジ日時 | 2024-10-11 22:17:57 |
| 合計ジャッジ時間 | 9,443 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
class combi:
def __init__(self,max_n,mod):
max_n+=1
self.mod=mod
self.fact=[0]*max_n
self.rev=[0]*max_n
self.fact_rev=[0]*max_n
self.fact[0]=1
self.rev[0]=1
self.fact_rev[0]=1
for i in range(max_n):
if i<=1:
self.fact[i]=1
self.rev[i]=1
self.fact_rev[i]=1
continue
self.fact[i]=(i*self.fact[i-1])%mod
self.rev[i]=mod-((mod//i)*self.rev[mod%i])%mod
self.fact_rev[i]=(self.fact_rev[i-1]*self.rev[i])%mod
def combination(self,a,b):
if a<b:
return 0
ans=(self.fact_rev[a-b]*self.fact_rev[b])%self.mod
return (ans*self.fact[a])%self.mod
H,W=map(int,input().split())
mod=10**9+7
C=combi(H,mod)
ans=0
tmp=1
for i in range(H+1):
b=1
if (i+H+W)%2==1:
b=-1
ans+=b*((C.combination(H,i)*pow(1-tmp,W,mod))%mod)
ans%=mod
tmp*=2
if tmp>=mod:
tmp-=mod
print(ans)
potato167