結果

問題 No.1126 SUM
ユーザー kozykozy
提出日時 2020-07-24 17:30:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 614 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 11,384 KB
最終ジャッジ日時 2023-09-08 04:20:54
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
8,516 KB
testcase_01 AC 76 ms
11,384 KB
testcase_02 AC 32 ms
9,288 KB
testcase_03 AC 23 ms
8,696 KB
testcase_04 AC 70 ms
11,100 KB
testcase_05 AC 64 ms
10,996 KB
testcase_06 AC 37 ms
9,484 KB
testcase_07 AC 23 ms
8,664 KB
testcase_08 AC 34 ms
9,244 KB
testcase_09 AC 56 ms
10,480 KB
testcase_10 AC 26 ms
8,660 KB
testcase_11 AC 21 ms
8,544 KB
testcase_12 AC 29 ms
8,928 KB
testcase_13 AC 25 ms
8,568 KB
testcase_14 AC 32 ms
8,972 KB
testcase_15 AC 29 ms
9,000 KB
testcase_16 AC 53 ms
10,276 KB
testcase_17 AC 40 ms
9,840 KB
testcase_18 AC 35 ms
9,116 KB
testcase_19 AC 58 ms
10,520 KB
testcase_20 AC 35 ms
9,204 KB
testcase_21 AC 56 ms
10,380 KB
testcase_22 AC 51 ms
10,340 KB
testcase_23 AC 68 ms
11,172 KB
testcase_24 AC 25 ms
8,548 KB
testcase_25 AC 16 ms
7,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    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 *= int(numerator[k])

    return result
N,M=map(int,input().split())
print(cmb(M+1,N+1)%1000000007)
0