結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー nebukuro09nebukuro09
提出日時 2016-10-25 14:49:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 6,660 KB
実行使用メモリ 13,024 KB
最終ジャッジ日時 2023-08-15 19:11:54
合計ジャッジ時間 6,541 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,988 KB
testcase_01 AC 12 ms
5,984 KB
testcase_02 AC 11 ms
6,024 KB
testcase_03 AC 11 ms
5,920 KB
testcase_04 AC 11 ms
6,100 KB
testcase_05 AC 11 ms
6,216 KB
testcase_06 AC 11 ms
5,948 KB
testcase_07 AC 11 ms
6,072 KB
testcase_08 AC 11 ms
5,912 KB
testcase_09 AC 115 ms
10,060 KB
testcase_10 AC 86 ms
9,024 KB
testcase_11 AC 171 ms
11,996 KB
testcase_12 AC 21 ms
6,308 KB
testcase_13 AC 72 ms
8,724 KB
testcase_14 AC 53 ms
7,400 KB
testcase_15 AC 55 ms
7,828 KB
testcase_16 AC 82 ms
8,904 KB
testcase_17 AC 158 ms
11,468 KB
testcase_18 AC 125 ms
10,844 KB
testcase_19 AC 11 ms
6,108 KB
testcase_20 AC 11 ms
6,224 KB
testcase_21 AC 12 ms
6,104 KB
testcase_22 AC 11 ms
6,108 KB
testcase_23 AC 11 ms
6,060 KB
testcase_24 AC 11 ms
6,024 KB
testcase_25 AC 11 ms
5,988 KB
testcase_26 AC 11 ms
5,972 KB
testcase_27 AC 12 ms
5,968 KB
testcase_28 AC 11 ms
6,056 KB
testcase_29 AC 11 ms
6,064 KB
testcase_30 AC 11 ms
6,216 KB
testcase_31 AC 12 ms
5,960 KB
testcase_32 AC 11 ms
5,916 KB
testcase_33 AC 12 ms
6,100 KB
testcase_34 AC 11 ms
6,108 KB
testcase_35 AC 11 ms
5,952 KB
testcase_36 AC 11 ms
6,028 KB
testcase_37 AC 11 ms
6,164 KB
testcase_38 AC 11 ms
5,920 KB
testcase_39 AC 11 ms
5,992 KB
testcase_40 AC 12 ms
5,964 KB
testcase_41 AC 11 ms
5,908 KB
testcase_42 AC 11 ms
6,172 KB
testcase_43 AC 11 ms
5,948 KB
testcase_44 AC 11 ms
6,016 KB
testcase_45 AC 12 ms
5,920 KB
testcase_46 AC 12 ms
5,968 KB
testcase_47 AC 11 ms
5,916 KB
testcase_48 AC 11 ms
6,016 KB
testcase_49 AC 132 ms
11,196 KB
testcase_50 AC 18 ms
6,728 KB
testcase_51 AC 17 ms
6,064 KB
testcase_52 AC 33 ms
9,124 KB
testcase_53 AC 21 ms
6,524 KB
testcase_54 AC 39 ms
9,652 KB
testcase_55 AC 12 ms
6,084 KB
testcase_56 AC 20 ms
6,224 KB
testcase_57 AC 62 ms
8,128 KB
testcase_58 AC 110 ms
10,392 KB
testcase_59 AC 88 ms
9,416 KB
testcase_60 AC 46 ms
7,356 KB
testcase_61 AC 175 ms
13,024 KB
testcase_62 AC 46 ms
7,636 KB
testcase_63 AC 114 ms
10,384 KB
testcase_64 AC 38 ms
9,408 KB
testcase_65 AC 28 ms
6,680 KB
testcase_66 AC 42 ms
7,296 KB
testcase_67 AC 40 ms
7,560 KB
testcase_68 AC 40 ms
9,772 KB
testcase_69 AC 11 ms
5,964 KB
testcase_70 AC 11 ms
6,020 KB
testcase_71 AC 12 ms
5,948 KB
testcase_72 AC 11 ms
6,020 KB
testcase_73 AC 11 ms
6,124 KB
testcase_74 AC 11 ms
5,956 KB
testcase_75 AC 11 ms
6,020 KB
testcase_76 AC 11 ms
5,992 KB
testcase_77 AC 11 ms
6,124 KB
testcase_78 AC 12 ms
6,180 KB
testcase_79 AC 11 ms
5,984 KB
testcase_80 AC 11 ms
6,116 KB
testcase_81 AC 11 ms
6,200 KB
testcase_82 AC 11 ms
5,956 KB
testcase_83 AC 11 ms
5,908 KB
testcase_84 AC 12 ms
6,224 KB
testcase_85 AC 11 ms
6,056 KB
testcase_86 AC 11 ms
6,024 KB
testcase_87 AC 11 ms
5,960 KB
testcase_88 AC 11 ms
6,016 KB
testcase_89 AC 51 ms
7,640 KB
testcase_90 AC 78 ms
8,868 KB
testcase_91 AC 128 ms
10,844 KB
testcase_92 AC 28 ms
6,716 KB
testcase_93 AC 86 ms
8,872 KB
testcase_94 AC 13 ms
6,312 KB
testcase_95 AC 90 ms
9,388 KB
testcase_96 AC 71 ms
8,712 KB
testcase_97 AC 68 ms
8,448 KB
testcase_98 AC 40 ms
9,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 1000000007

def ncr(n, r):
    if n - r < r:
        r = n-r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [0 for i in range(r)]
    denominator = [0 for i in range(r)]

    for k in range(r):
        numerator[k] = n - r + k + 1
        denominator[k] = k + 1
    
    for p in range(2, r+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (n-r) % p
        for k in range(p-1, r, p):
            numerator[k-offset] /= pivot
            denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result*numerator[k]) % MOD

    return result

M = input()
H = map(int, raw_input().split())
blank = M - sum(H) - len(H) + 1
if blank < 0:
    print 'NA'
    exit()
if H[0] == 0:
    print 1
    exit()
print ncr(len(H)+blank, blank)
0