結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-08 23:11:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 118,784 KB
最終ジャッジ日時 2024-04-21 07:52:33
合計ジャッジ時間 11,066 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,968 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 39 ms
51,840 KB
testcase_04 AC 344 ms
99,788 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 39 ms
52,224 KB
testcase_07 AC 39 ms
51,968 KB
testcase_08 AC 40 ms
52,608 KB
testcase_09 AC 353 ms
105,324 KB
testcase_10 AC 100 ms
79,252 KB
testcase_11 AC 344 ms
105,468 KB
testcase_12 AC 75 ms
77,568 KB
testcase_13 AC 154 ms
89,748 KB
testcase_14 AC 93 ms
79,056 KB
testcase_15 AC 105 ms
79,932 KB
testcase_16 AC 187 ms
88,876 KB
testcase_17 AC 249 ms
96,420 KB
testcase_18 AC 231 ms
109,252 KB
testcase_19 AC 39 ms
52,608 KB
testcase_20 AC 39 ms
52,352 KB
testcase_21 AC 39 ms
52,352 KB
testcase_22 AC 44 ms
59,136 KB
testcase_23 AC 40 ms
52,736 KB
testcase_24 AC 52 ms
59,520 KB
testcase_25 AC 40 ms
52,864 KB
testcase_26 AC 47 ms
58,752 KB
testcase_27 AC 48 ms
59,264 KB
testcase_28 AC 44 ms
52,352 KB
testcase_29 AC 42 ms
52,352 KB
testcase_30 AC 42 ms
52,736 KB
testcase_31 AC 40 ms
52,608 KB
testcase_32 AC 41 ms
52,864 KB
testcase_33 AC 40 ms
52,352 KB
testcase_34 AC 44 ms
58,880 KB
testcase_35 AC 41 ms
52,352 KB
testcase_36 AC 41 ms
52,608 KB
testcase_37 AC 41 ms
52,480 KB
testcase_38 AC 40 ms
52,480 KB
testcase_39 AC 40 ms
52,352 KB
testcase_40 AC 43 ms
58,624 KB
testcase_41 AC 39 ms
52,224 KB
testcase_42 AC 41 ms
52,480 KB
testcase_43 AC 39 ms
52,096 KB
testcase_44 AC 38 ms
52,992 KB
testcase_45 AC 39 ms
52,224 KB
testcase_46 AC 45 ms
59,264 KB
testcase_47 AC 37 ms
52,864 KB
testcase_48 AC 38 ms
52,224 KB
testcase_49 AC 118 ms
110,416 KB
testcase_50 AC 48 ms
64,768 KB
testcase_51 AC 51 ms
64,768 KB
testcase_52 AC 64 ms
78,728 KB
testcase_53 AC 53 ms
69,120 KB
testcase_54 AC 66 ms
79,536 KB
testcase_55 AC 45 ms
59,776 KB
testcase_56 AC 58 ms
67,456 KB
testcase_57 AC 82 ms
86,404 KB
testcase_58 AC 112 ms
105,560 KB
testcase_59 AC 100 ms
97,264 KB
testcase_60 AC 73 ms
81,600 KB
testcase_61 AC 150 ms
118,784 KB
testcase_62 AC 75 ms
82,468 KB
testcase_63 AC 117 ms
106,244 KB
testcase_64 AC 68 ms
79,416 KB
testcase_65 AC 59 ms
75,008 KB
testcase_66 AC 74 ms
81,952 KB
testcase_67 AC 70 ms
80,696 KB
testcase_68 AC 70 ms
80,112 KB
testcase_69 AC 204 ms
89,240 KB
testcase_70 AC 123 ms
82,896 KB
testcase_71 AC 159 ms
84,668 KB
testcase_72 AC 100 ms
80,356 KB
testcase_73 AC 137 ms
82,820 KB
testcase_74 AC 169 ms
85,660 KB
testcase_75 AC 160 ms
84,532 KB
testcase_76 AC 94 ms
78,804 KB
testcase_77 AC 243 ms
93,388 KB
testcase_78 AC 69 ms
76,032 KB
testcase_79 AC 39 ms
52,224 KB
testcase_80 AC 40 ms
52,224 KB
testcase_81 AC 39 ms
52,224 KB
testcase_82 AC 39 ms
52,224 KB
testcase_83 AC 38 ms
52,480 KB
testcase_84 AC 38 ms
52,224 KB
testcase_85 AC 41 ms
52,096 KB
testcase_86 AC 40 ms
51,968 KB
testcase_87 AC 41 ms
52,224 KB
testcase_88 AC 44 ms
52,480 KB
testcase_89 AC 127 ms
83,892 KB
testcase_90 AC 172 ms
95,328 KB
testcase_91 AC 240 ms
109,952 KB
testcase_92 AC 87 ms
79,296 KB
testcase_93 AC 179 ms
97,424 KB
testcase_94 AC 58 ms
67,072 KB
testcase_95 AC 184 ms
99,240 KB
testcase_96 AC 155 ms
87,776 KB
testcase_97 AC 145 ms
87,948 KB
testcase_98 AC 105 ms
80,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import array

P = 10 ** 9 + 7


# Based on http://hos.ac/slides/20130319_enumeration.pdf
def main():
    m = int(input())
    hs = array.array("L", map(int, input().split()))
    if hs[0] == 0:
        print(1)
        return
    k = len(hs)
    s = sum(hs)
    if s + k - 1 > m:
        print("NA")
        return
    n = m + 1 - s
    inv = array.array("L", (0 for _ in range(n + 1)))
    inv[1] = 1
    for i in range(2, n + 1):
        inv[i] = P - (P // i) * inv[P % i] % P
    fac = array.array("L", (0 for _ in range(n + 1)))
    facinv = array.array("L", (0 for _ in range(n + 1)))
    fac[0] = 1
    facinv[0] = 1
    for i in range(1, n + 1):
        fac[i] = (fac[i - 1] * i) % P
        facinv[i] = (facinv[i - 1] * inv[i]) % P
    if not (0 <= k and k <= n):
        binom = 0
    else:
        binom = (((fac[n] * facinv[k]) % P) * facinv[n - k]) % P
    print(binom)


if __name__ == '__main__':
    main()
0