結果
問題 | No.243 出席番号(2) |
ユーザー | Min_25 |
提出日時 | 2016-04-23 20:23:00 |
言語 | Python2 (2.7.18) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,683 bytes |
コンパイル時間 | 138 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-10-04 15:22:41 |
合計ジャッジ時間 | 1,733 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
6,820 KB |
testcase_01 | AC | 9 ms
6,820 KB |
testcase_02 | AC | 9 ms
6,816 KB |
testcase_03 | AC | 13 ms
6,816 KB |
testcase_04 | AC | 11 ms
6,820 KB |
testcase_05 | AC | 10 ms
6,816 KB |
testcase_06 | AC | 11 ms
6,820 KB |
testcase_07 | RE | - |
testcase_08 | AC | 19 ms
6,820 KB |
testcase_09 | AC | 15 ms
6,816 KB |
testcase_10 | AC | 12 ms
6,820 KB |
testcase_11 | AC | 12 ms
6,816 KB |
testcase_12 | RE | - |
testcase_13 | AC | 26 ms
6,816 KB |
testcase_14 | AC | 15 ms
6,816 KB |
testcase_15 | AC | 13 ms
6,820 KB |
testcase_16 | AC | 12 ms
6,816 KB |
testcase_17 | RE | - |
testcase_18 | AC | 32 ms
6,816 KB |
testcase_19 | AC | 16 ms
6,820 KB |
testcase_20 | AC | 14 ms
6,816 KB |
testcase_21 | AC | 13 ms
6,816 KB |
testcase_22 | RE | - |
testcase_23 | AC | 40 ms
6,820 KB |
testcase_24 | AC | 19 ms
6,820 KB |
testcase_25 | AC | 15 ms
6,816 KB |
testcase_26 | AC | 13 ms
6,820 KB |
testcase_27 | AC | 69 ms
6,912 KB |
testcase_28 | AC | 10 ms
6,816 KB |
testcase_29 | AC | 9 ms
6,816 KB |
testcase_30 | AC | 9 ms
6,820 KB |
testcase_31 | AC | 10 ms
6,816 KB |
testcase_32 | AC | 9 ms
6,824 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] * N 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()