結果
問題 | No.1846 Good Binary Matrix |
ユーザー |
👑 ![]() |
提出日時 | 2021-12-07 08:58:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 666 ms / 2,000 ms |
コード長 | 965 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 82,096 KB |
実行使用メモリ | 84,864 KB |
最終ジャッジ日時 | 2024-07-07 10:20:01 |
合計ジャッジ時間 | 8,816 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
class combi:def __init__(self,max_n,mod):max_n+=1self.mod=modself.fact=[0]*max_nself.rev=[0]*max_nself.fact_rev=[0]*max_nself.fact[0]=1self.rev[0]=1self.fact_rev[0]=1for i in range(max_n):if i<=1:self.fact[i]=1self.rev[i]=1self.fact_rev[i]=1continueself.fact[i]=(i*self.fact[i-1])%modself.rev[i]=mod-((mod//i)*self.rev[mod%i])%modself.fact_rev[i]=(self.fact_rev[i-1]*self.rev[i])%moddef combination(self,a,b):if a<b:return 0ans=(self.fact_rev[a-b]*self.fact_rev[b])%self.modreturn (ans*self.fact[a])%self.modM=10**9+7H,W=map(int,input().split())table=combi(W+1,M)tmp=1sign=pow(-1,H+W)ans=0for i in range(W+1):ans+=(table.combination(W,i)*sign*pow(1-tmp,H,M))%Msign*=-1tmp=(tmp*2)%Mans%=Mprint(ans)