Submission #6911627
Source Code Expand
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 class FactInvMOD: """ 階乗たくさん使う時用のテーブル準備 """ def __init__(self, MAX, MOD): """ MAX:階乗に使う数値の最大以上まで作る """ MAX += 1 self.MAX = MAX self.MOD = MOD # 階乗テーブル factorial = [1] * MAX factorial[0] = factorial[1] = 1 for i in range(2, MAX): factorial[i] = factorial[i-1] * i % MOD # 階乗の逆元テーブル inverse = [1] * MAX # powに第三引数入れると冪乗のmod付計算を高速にやってくれる inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD) for i in range(MAX-2, 0, -1): # 最後から戻っていくこのループならMAX回powするより処理が速い inverse[i] = inverse[i+1] * (i+1) % MOD self.fact = factorial self.inv = inverse def nCr(self, n, r): """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """ if n < r: return 0 # あり得ない状況が来たら0を返す if n < 0 or r < 0: return 0 # 10C7 = 10C3 r = min(r, n-r) # 分子の計算 numerator = self.fact[n] # 分母の計算 denominator = self.inv[r] * self.inv[n-r] % self.MOD return numerator * denominator % self.MOD def nPr(self, n, r): """ 順列 """ if n < r: return 0 return self.fact[n] * self.inv[n-r] % self.MOD def nHr(self, n, r): """ 重複組み合わせ """ # r個選ぶところにN-1個の仕切りを入れる return self.nCr(r+n-1, r) def bit_cnt(i): i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) i = (i + (i >> 4)) & 0x0f0f0f0f i = i + (i >> 8) i = i + (i >> 16) return i & 0x3f R, C = MAP() X, Y = MAP() D, L = MAP() fim = FactInvMOD(X*Y, MOD) # 区画内でのデスク、ラック、空白の配置の全パターン数 total = fim.nCr(X*Y, D+L) * fim.nCr(D+L, D) % MOD ng = 0 for i in range(1, 1<<4): # 行列を減らす数 offsetx = 0 offsety = 0 if i>>0 & 1: offsetx += 1 if i>>1 & 1: offsetx += 1 if i>>2 & 1: offsety += 1 if i>>3 & 1: offsety += 1 # ありえないパターンを除外 if X-offsetx < 0 or Y-offsety < 0: continue # 今回の行列数での通り数 cnt = fim.nCr((X-offsetx)*(Y-offsety), D+L) * fim.nCr(D+L, D) % MOD # 包徐原理で通り数を加減する # 立っているビットを数えれば、共通領域の偶奇が分かる if bit_cnt(i)%2 == 0: ng -= cnt else: ng += cnt ng %= MOD ok = (total - ng) % MOD # 区画内での配置の通り数 * 部屋全体から区画を配置する通り数 print(ok*(R-X+1)*(C-Y+1)%MOD)
Submission Info
Submission Time | |
---|---|
Task | D - AtCoder社の冬 |
User | Coki628 |
Language | Python (3.4.3) |
Score | 101 |
Code Size | 3571 Byte |
Status | AC |
Exec Time | 19 ms |
Memory | 3192 KB |
Judge Result
Set Name | sub | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 100 / 100 | 1 / 1 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sub | 00_sample_01E.txt, 00_sample_02E.txt, 00_sample_03E.txt, test_03E.txt, test_04E.txt, test_07E.txt, test_08E.txt, test_11E.txt, test_12E.txt, test_15E.txt, test_16E.txt, test_19E.txt, test_20E.txt, test_23E.txt, test_24E.txt, test_27E.txt, test_28E.txt, test_31E.txt, test_32E.txt, test_36E.txt, test_37E.txt, test_38E.txt, test_39E.txt, test_45E.txt, test_47E.txt |
All | 00_sample_01E.txt, 00_sample_02E.txt, 00_sample_03E.txt, 00_sample_04.txt, test_01.txt, test_02.txt, test_03E.txt, test_04E.txt, test_05.txt, test_06.txt, test_07E.txt, test_08E.txt, test_09.txt, test_10.txt, test_11E.txt, test_12E.txt, test_13.txt, test_14.txt, test_15E.txt, test_16E.txt, test_17.txt, test_18.txt, test_19E.txt, test_20E.txt, test_21.txt, test_22.txt, test_23E.txt, test_24E.txt, test_25.txt, test_26.txt, test_27E.txt, test_28E.txt, test_29.txt, test_30.txt, test_31E.txt, test_32E.txt, test_33.txt, test_34.txt, test_35.txt, test_36E.txt, test_37E.txt, test_38E.txt, test_39E.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45E.txt, test_46.txt, test_47E.txt, test_48.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01E.txt | AC | 18 ms | 3192 KB |
00_sample_02E.txt | AC | 18 ms | 3192 KB |
00_sample_03E.txt | AC | 18 ms | 3192 KB |
00_sample_04.txt | AC | 18 ms | 3192 KB |
test_01.txt | AC | 18 ms | 3192 KB |
test_02.txt | AC | 18 ms | 3192 KB |
test_03E.txt | AC | 18 ms | 3192 KB |
test_04E.txt | AC | 18 ms | 3192 KB |
test_05.txt | AC | 18 ms | 3192 KB |
test_06.txt | AC | 18 ms | 3192 KB |
test_07E.txt | AC | 18 ms | 3192 KB |
test_08E.txt | AC | 18 ms | 3192 KB |
test_09.txt | AC | 18 ms | 3192 KB |
test_10.txt | AC | 18 ms | 3192 KB |
test_11E.txt | AC | 18 ms | 3192 KB |
test_12E.txt | AC | 18 ms | 3192 KB |
test_13.txt | AC | 18 ms | 3192 KB |
test_14.txt | AC | 18 ms | 3192 KB |
test_15E.txt | AC | 18 ms | 3192 KB |
test_16E.txt | AC | 19 ms | 3192 KB |
test_17.txt | AC | 18 ms | 3192 KB |
test_18.txt | AC | 18 ms | 3192 KB |
test_19E.txt | AC | 18 ms | 3192 KB |
test_20E.txt | AC | 18 ms | 3192 KB |
test_21.txt | AC | 18 ms | 3192 KB |
test_22.txt | AC | 18 ms | 3192 KB |
test_23E.txt | AC | 18 ms | 3192 KB |
test_24E.txt | AC | 18 ms | 3192 KB |
test_25.txt | AC | 18 ms | 3192 KB |
test_26.txt | AC | 18 ms | 3192 KB |
test_27E.txt | AC | 18 ms | 3192 KB |
test_28E.txt | AC | 18 ms | 3192 KB |
test_29.txt | AC | 18 ms | 3192 KB |
test_30.txt | AC | 19 ms | 3192 KB |
test_31E.txt | AC | 18 ms | 3192 KB |
test_32E.txt | AC | 18 ms | 3192 KB |
test_33.txt | AC | 18 ms | 3192 KB |
test_34.txt | AC | 18 ms | 3192 KB |
test_35.txt | AC | 18 ms | 3192 KB |
test_36E.txt | AC | 18 ms | 3192 KB |
test_37E.txt | AC | 18 ms | 3192 KB |
test_38E.txt | AC | 18 ms | 3192 KB |
test_39E.txt | AC | 18 ms | 3192 KB |
test_40.txt | AC | 18 ms | 3192 KB |
test_41.txt | AC | 18 ms | 3192 KB |
test_42.txt | AC | 18 ms | 3192 KB |
test_43.txt | AC | 18 ms | 3192 KB |
test_44.txt | AC | 18 ms | 3192 KB |
test_45E.txt | AC | 18 ms | 3192 KB |
test_46.txt | AC | 18 ms | 3192 KB |
test_47E.txt | AC | 18 ms | 3192 KB |
test_48.txt | AC | 18 ms | 3192 KB |