結果

問題 No.391 CODING WAR
ユーザー shotoyooshotoyoo
提出日時 2021-06-23 22:41:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 81,908 KB
最終ジャッジ日時 2023-09-07 04:28:19
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,268 KB
testcase_01 AC 70 ms
71,380 KB
testcase_02 AC 75 ms
71,056 KB
testcase_03 AC 70 ms
71,056 KB
testcase_04 AC 70 ms
71,444 KB
testcase_05 AC 74 ms
71,396 KB
testcase_06 AC 71 ms
71,464 KB
testcase_07 AC 71 ms
71,380 KB
testcase_08 AC 72 ms
71,144 KB
testcase_09 AC 176 ms
81,888 KB
testcase_10 AC 155 ms
81,892 KB
testcase_11 AC 79 ms
78,644 KB
testcase_12 AC 67 ms
71,372 KB
testcase_13 AC 162 ms
81,908 KB
testcase_14 AC 159 ms
80,528 KB
testcase_15 AC 168 ms
81,180 KB
testcase_16 AC 136 ms
79,296 KB
testcase_17 AC 143 ms
79,732 KB
testcase_18 AC 125 ms
78,184 KB
testcase_19 AC 125 ms
78,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,m = list(map(int, input().split()))
M = 10**9+7
### 素数の逆元とCombination

M = 10**9+7 # 出力の制限
# M = 998244353
N = m+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M

if m>n:
    ans = 0
else:
    ans = 0
    s = 1
    for i in range(m):
        ans += s * pow(m-i, n, M) * cmb(m,i) % M
        ans %= M
        s *= -1
print(ans%M)
0