結果
| 問題 | 
                            No.1846 Good Binary Matrix
                             | 
                    
| コンテスト | |
| ユーザー | 
                             asumo0729
                         | 
                    
| 提出日時 | 2022-02-18 22:42:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,655 bytes | 
| コンパイル時間 | 221 ms | 
| コンパイル使用メモリ | 82,140 KB | 
| 実行使用メモリ | 279,160 KB | 
| 最終ジャッジ日時 | 2024-06-29 09:28:21 | 
| 合計ジャッジ時間 | 12,563 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 TLE * 10 | 
ソースコード
import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
import bisect
import math
import itertools
import copy
stdin=sys.stdin
sys.setrecursionlimit(10 ** 8)
ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
inf = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
eps = 1e-9
sortkey1 = itemgetter(0)
sortkey2 = lambda x: (x[0], x[1])
class Comb():
    def __init__(self, N, mod):
        self.N = N
        self.mod = mod
        self.fa = self.fa_fainv()[0]
        self.fainv = self.fa_fainv()[1]
    def fa_fainv(self):
        fa = [1]
        for i in range(1, self.N + 1):
            fa.append(fa[-1] * i % self.mod)
        fainv = [pow(fa[-1],self.mod - 2,self.mod)]
        for i in range(1, self.N + 1)[::-1]:
            fainv.append(fainv[-1] * i % self.mod)
        fainv = fainv[::-1]
        return fa, fainv
    def aCb(self, a, b):
        if b < 0 or a < b: 
            return 0
        return self.fa[a] * self.fainv[a - b] * self.fainv[b] % self.mod
    def aPb(self, a, b):
        if b < 0 or a < b: 
            return 0
        return self.fa[a] * self.fainv[a - b]
###############################################################
H, W = lp()
comb = Comb(2 * 10 ** 6 + 10, mod)
ans = 0
for i in range(H + 1):
    s = (-1) ** (i % 2)
    p = pow(2, H - i, mod)
    p = pow(p, mod - 2, mod)
    C = comb.aCb(H, i) * pow(2, H * W - W * i, mod)
    r = pow(1 - p , W, mod)
    q = s * C * r
    q %= mod
    ans += q
    ans %= mod
print(ans)
            
            
            
        
            
asumo0729