結果
問題 | No.243 出席番号(2) |
ユーザー | Min_25 |
提出日時 | 2016-04-23 20:47:32 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 110 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-10-04 15:22:54 |
合計ジャッジ時間 | 1,926 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
6,820 KB |
testcase_01 | AC | 11 ms
6,820 KB |
testcase_02 | AC | 10 ms
6,820 KB |
testcase_03 | AC | 13 ms
6,816 KB |
testcase_04 | AC | 11 ms
6,816 KB |
testcase_05 | AC | 12 ms
6,816 KB |
testcase_06 | AC | 11 ms
6,816 KB |
testcase_07 | AC | 12 ms
6,820 KB |
testcase_08 | AC | 17 ms
6,816 KB |
testcase_09 | AC | 16 ms
6,816 KB |
testcase_10 | AC | 14 ms
6,820 KB |
testcase_11 | AC | 13 ms
6,816 KB |
testcase_12 | AC | 15 ms
6,816 KB |
testcase_13 | AC | 25 ms
6,820 KB |
testcase_14 | AC | 18 ms
6,816 KB |
testcase_15 | AC | 17 ms
6,820 KB |
testcase_16 | AC | 14 ms
6,820 KB |
testcase_17 | AC | 22 ms
6,820 KB |
testcase_18 | AC | 27 ms
6,820 KB |
testcase_19 | AC | 20 ms
6,824 KB |
testcase_20 | AC | 18 ms
6,820 KB |
testcase_21 | AC | 16 ms
6,820 KB |
testcase_22 | AC | 30 ms
7,040 KB |
testcase_23 | AC | 31 ms
7,040 KB |
testcase_24 | AC | 23 ms
6,912 KB |
testcase_25 | AC | 21 ms
6,816 KB |
testcase_26 | AC | 18 ms
6,816 KB |
testcase_27 | AC | 40 ms
7,296 KB |
testcase_28 | AC | 9 ms
6,816 KB |
testcase_29 | AC | 10 ms
6,816 KB |
testcase_30 | AC | 10 ms
6,816 KB |
testcase_31 | AC | 10 ms
6,816 KB |
testcase_32 | AC | 10 ms
6,816 KB |
ソースコード
def ilog2(n): return 0 if n <= 0 else n.bit_length() - 1 def pack(pack, shamt): size = len(pack) while size > 1: npack = [] for i in range(0, size - 1, 2): npack += [pack[i] | (pack[i+1] << shamt)] if size & 1: npack += [pack[-1]] pack, size, shamt = npack, (size + 1) >> 1, shamt << 1 return pack[0] def unpack(M, size, shamt): s, sizes = size, [] while s > 1: sizes += [s] s = (s + 1) >> 1 ret = [M] for size in sizes[::-1]: mask, nret = (1 << shamt) - 1, [] for c in ret: nret += [c & mask, c >> shamt] ret, shamt = nret[:size], shamt >> 1 return ret def poly_mul_mod(f, g, mod): size = min(len(f), len(g)) shift = ((mod - 1) ** 2 * size).bit_length() rsize = len(f) + len(g) - 1 h = unpack(pack(f, shift) * pack(g, shift), rsize, shift * (1 << ilog2(rsize - 1))) return [int(x % mod) for x in h] def prob243(): from sys import stdin N = int(stdin.readline()) MOD = 10 ** 9 + 7 cnts = [0] * 5000 for line in stdin: a = int(line) cnts[a] += 1 rcnts = [0] * (N + 1) for i in range(N): if cnts[i]: rcnts[cnts[i]] += 1 invs = [1] * (N + 2) for i in range(2, N + 2): invs[i] = invs[MOD % i] * (MOD - MOD // i) % MOD poly = [1] for i in range(1, N + 1): if rcnts[i]: f = [] c = 1 M = rcnts[i] for j in range(M + 1): f += [c % MOD] c = c * (M - j) % MOD * invs[j + 1] % MOD * i % MOD poly = poly_mul_mod(poly, f, MOD) facts = [1] for i in range(1, N + 1): facts += [facts[-1] * i % MOD] ans = 0 for i in range(len(poly)): ans += (-1) ** i * poly[i] * facts[-1 - i] % MOD print(ans % MOD) prob243()