結果
問題 | No.243 出席番号(2) |
ユーザー | Min_25 |
提出日時 | 2016-04-23 20:24:43 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 1,686 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-10-04 15:22:48 |
合計ジャッジ時間 | 1,550 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
6,816 KB |
testcase_01 | AC | 11 ms
6,816 KB |
testcase_02 | AC | 11 ms
6,816 KB |
testcase_03 | AC | 14 ms
6,816 KB |
testcase_04 | AC | 12 ms
6,816 KB |
testcase_05 | AC | 10 ms
6,816 KB |
testcase_06 | AC | 9 ms
6,820 KB |
testcase_07 | AC | 12 ms
6,820 KB |
testcase_08 | AC | 18 ms
6,816 KB |
testcase_09 | AC | 13 ms
6,820 KB |
testcase_10 | AC | 12 ms
6,816 KB |
testcase_11 | AC | 10 ms
6,820 KB |
testcase_12 | AC | 20 ms
6,816 KB |
testcase_13 | AC | 24 ms
6,816 KB |
testcase_14 | AC | 15 ms
6,816 KB |
testcase_15 | AC | 12 ms
6,820 KB |
testcase_16 | AC | 12 ms
6,820 KB |
testcase_17 | AC | 34 ms
6,820 KB |
testcase_18 | AC | 30 ms
6,816 KB |
testcase_19 | AC | 17 ms
6,820 KB |
testcase_20 | AC | 14 ms
6,816 KB |
testcase_21 | AC | 12 ms
6,820 KB |
testcase_22 | AC | 53 ms
6,816 KB |
testcase_23 | AC | 36 ms
6,912 KB |
testcase_24 | AC | 20 ms
6,816 KB |
testcase_25 | AC | 16 ms
6,816 KB |
testcase_26 | AC | 15 ms
6,820 KB |
testcase_27 | AC | 70 ms
6,816 KB |
testcase_28 | AC | 10 ms
6,816 KB |
testcase_29 | AC | 9 ms
6,816 KB |
testcase_30 | AC | 10 ms
6,816 KB |
testcase_31 | AC | 9 ms
6,816 KB |
testcase_32 | AC | 9 ms
6,820 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 poly_coefficients_mod(roots, mod): def rec(beg, end): if end - beg == 1: return [1, -roots[beg] % mod] else: mid = (beg + end) // 2 return poly_mul_mod(rec(beg, mid), rec(mid, end), mod) if not roots: return [1] ret = [0] * (len(roots) + 1) return rec(0, len(roots)) 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 roots = [] for i in range(N): if cnts[i]: roots += [-cnts[i]] poly = poly_coefficients_mod(roots, 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()