結果
問題 | No.767 配られたジャパリまん |
ユーザー | ayaoni |
提出日時 | 2021-08-04 04:34:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 814 ms / 2,000 ms |
コード長 | 2,085 bytes |
コンパイル時間 | 473 ms |
コンパイル使用メモリ | 87,096 KB |
実行使用メモリ | 138,168 KB |
最終ジャッジ日時 | 2023-10-14 21:12:39 |
合計ジャッジ時間 | 4,937 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
70,976 KB |
testcase_01 | AC | 75 ms
71,216 KB |
testcase_02 | AC | 76 ms
70,804 KB |
testcase_03 | AC | 75 ms
71,348 KB |
testcase_04 | AC | 103 ms
76,340 KB |
testcase_05 | AC | 166 ms
89,204 KB |
testcase_06 | AC | 76 ms
71,032 KB |
testcase_07 | AC | 75 ms
71,392 KB |
testcase_08 | AC | 81 ms
76,224 KB |
testcase_09 | AC | 106 ms
79,024 KB |
testcase_10 | AC | 136 ms
83,192 KB |
testcase_11 | AC | 116 ms
84,236 KB |
testcase_12 | AC | 115 ms
82,168 KB |
testcase_13 | AC | 135 ms
82,400 KB |
testcase_14 | AC | 109 ms
84,712 KB |
testcase_15 | AC | 92 ms
86,388 KB |
testcase_16 | AC | 116 ms
83,392 KB |
testcase_17 | AC | 83 ms
78,400 KB |
testcase_18 | AC | 86 ms
79,296 KB |
testcase_19 | AC | 122 ms
86,628 KB |
testcase_20 | AC | 814 ms
138,168 KB |
ソースコード
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) H,W,k = MI() mod = 10**8+7 friends = [] for _ in range(k): a,b = MI() friends.append((W+1)*a+b) fac = [1] for i in range(1,H+W+1): fac.append((fac[-1]*i) % mod) fac_inv = [0]*(H+W+1) f = pow(fac[-1],mod-2,mod) for i in range(H+W,-1,-1): fac_inv[i] = f f *= i f %= mod def comb(n,r): return fac[n] * fac_inv[r] % mod * fac_inv[n-r] % mod K = 1 << k F = [0]*K for i in range(K): X = [0] for j in range(k): if not (i >> j) & 1: X.append(friends[j]) X.sort() X.append((W+1)*H+W) f = 1 for j in range(len(X)-1): a0,b0 = divmod(X[j],W+1) a1,b1 = divmod(X[j+1],W+1) if a0 > a1 or b0 > b1: break f *= comb((a1-a0)+(b1-b0),a1-a0) f %= mod else: F[i] = f def mobius_transform(F,n): # res[i] = (iを含む集合jに対する (-1)^(#j-#i)F[j] の和) N = 1 << n res = F[:] for i in range(n): k = 1 << i for j in range(N): if not j & k: res[j] -= res[j^k] res[j] %= mod return res G = mobius_transform(F,k)[::-1] def bit_count(n): c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f) c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff) c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff) c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff) return c for i in range(K): if bit_count(i) % 2 == 1: G[i] = (-G[i]) % mod print(*G,sep='\n')