結果
問題 |
No.287 場合の数
|
ユーザー |
![]() |
提出日時 | 2017-08-16 21:49:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,074 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 366,764 KB |
最終ジャッジ日時 | 2024-10-13 13:02:37 |
合計ジャッジ時間 | 12,772 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 21 |
ソースコード
# Functions def partition(n): if n == 1: return [[1]] sets = partition(n-1) results = [] for set in sets: s = len(set) if 1 < s and set[s-1] < set[s-2]: copy = list(set) copy[s-1] += 1 results.append(copy) set.append(1) results.append(set) results.append([n]) return results def factorial(n): result = 1 for i in range(1,n+1): result *= i return result # Main N = int(input()) sets = partition(N*6) results = [] for set in sets: if set[0] <= N and len(set) <= 8: while len(set) < 8: set.append(0) results.append(set) combs = [] for result in results: comb = {} for number in result: if number in comb: comb[number] += 1 else: comb[number] = 1 combs.append(comb) numerator = factorial(8) result = 0 for comb in combs: denominator = 1 for c in comb.keys(): denominator *= factorial(comb[c]) result += numerator//denominator print(result)