結果

問題 No.1035 Color Box
ユーザー jensenjensen
提出日時 2021-01-17 10:50:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 15,996 KB
最終ジャッジ日時 2023-08-19 14:38:36
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
15,868 KB
testcase_01 AC 16 ms
7,836 KB
testcase_02 AC 15 ms
7,784 KB
testcase_03 AC 33 ms
8,788 KB
testcase_04 AC 37 ms
8,904 KB
testcase_05 AC 21 ms
8,224 KB
testcase_06 AC 16 ms
7,964 KB
testcase_07 AC 17 ms
7,804 KB
testcase_08 AC 254 ms
14,904 KB
testcase_09 AC 108 ms
10,864 KB
testcase_10 AC 15 ms
7,812 KB
testcase_11 AC 15 ms
7,836 KB
testcase_12 AC 15 ms
7,788 KB
testcase_13 AC 206 ms
13,320 KB
testcase_14 AC 241 ms
14,080 KB
testcase_15 AC 283 ms
15,912 KB
testcase_16 AC 15 ms
7,788 KB
testcase_17 AC 15 ms
7,788 KB
testcase_18 AC 14 ms
7,856 KB
testcase_19 AC 283 ms
15,996 KB
testcase_20 AC 15 ms
7,968 KB
testcase_21 AC 15 ms
7,960 KB
testcase_22 AC 14 ms
7,848 KB
testcase_23 AC 14 ms
7,928 KB
testcase_24 AC 14 ms
7,832 KB
testcase_25 AC 14 ms
7,768 KB
testcase_26 AC 15 ms
7,940 KB
testcase_27 AC 14 ms
7,908 KB
testcase_28 AC 14 ms
7,852 KB
testcase_29 AC 14 ms
7,788 KB
testcase_30 AC 15 ms
7,876 KB
testcase_31 AC 15 ms
7,832 KB
testcase_32 AC 14 ms
7,924 KB
testcase_33 AC 15 ms
7,772 KB
testcase_34 AC 14 ms
7,908 KB
testcase_35 AC 14 ms
7,784 KB
testcase_36 AC 14 ms
7,916 KB
testcase_37 AC 14 ms
7,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prepare(n, MOD):
 
    # n! の計算
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
     
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return fn, invs

def cmb(n,r,fn,invs,mod):
    return fn*invs[r]*invs[n-r]%mod

n,m=map(int,input().split())
mod=10**9+7
fn,invs=prepare(m,mod)
a=[0]*(m+1)
for i in range(1,m+1):
    a[i]=(cmb(m,i,fn,invs,mod)*pow(i,n,mod)-a[i-1])%mod
print(a[m])
0