結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:20:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 1,045 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 151,700 KB |
最終ジャッジ日時 | 2025-03-20 21:21:28 |
合計ジャッジ時間 | 10,470 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 |
ソースコード
MOD = 10**9 + 7max_fact = 10**6 # Since M can be up to 1e6, and n = D +k can be up to 1e6# Precompute factorial and inverse factorial modulo MODfact = [1] * (max_fact + 1)for i in range(1, max_fact + 1):fact[i] = fact[i-1] * i % MODinv_fact = [1] * (max_fact + 1)inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD)for i in range(max_fact - 1, -1, -1):inv_fact[i] = inv_fact[i + 1] * (i + 1) % MODdef main():import sysinput = sys.stdin.read().split()M = int(input[0])H = list(map(int, input[1:]))if len(H) == 1 and H[0] == 0:print(1)returnif any(h <= 0 for h in H):print("NA")returnsum_h = sum(H)k = len(H)required = sum_h + (k - 1)if required > M:print("NA")returnD = M - requiredn = D + kif n > max_fact:print("NA")returncomb = fact[n] * inv_fact[k] % MODcomb = comb * inv_fact[n - k] % MODprint(comb)if __name__ == "__main__":main()