結果

問題 No.1035 Color Box
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-04-24 22:42:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 248,184 KB
最終ジャッジ日時 2024-04-23 03:43:23
合計ジャッジ時間 12,336 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
247,832 KB
testcase_01 AC 263 ms
246,756 KB
testcase_02 AC 251 ms
246,796 KB
testcase_03 AC 298 ms
248,096 KB
testcase_04 AC 308 ms
248,032 KB
testcase_05 AC 296 ms
247,056 KB
testcase_06 AC 267 ms
248,024 KB
testcase_07 AC 273 ms
246,484 KB
testcase_08 AC 442 ms
246,896 KB
testcase_09 AC 357 ms
247,204 KB
testcase_10 AC 251 ms
246,720 KB
testcase_11 AC 243 ms
247,828 KB
testcase_12 AC 241 ms
247,088 KB
testcase_13 AC 391 ms
247,992 KB
testcase_14 AC 436 ms
246,344 KB
testcase_15 AC 428 ms
247,512 KB
testcase_16 AC 246 ms
247,052 KB
testcase_17 AC 245 ms
247,704 KB
testcase_18 AC 242 ms
246,876 KB
testcase_19 AC 440 ms
247,400 KB
testcase_20 AC 244 ms
248,148 KB
testcase_21 AC 242 ms
247,460 KB
testcase_22 AC 248 ms
246,924 KB
testcase_23 AC 247 ms
247,120 KB
testcase_24 AC 252 ms
247,180 KB
testcase_25 AC 239 ms
247,936 KB
testcase_26 AC 241 ms
247,168 KB
testcase_27 AC 239 ms
246,356 KB
testcase_28 AC 248 ms
246,832 KB
testcase_29 AC 243 ms
246,928 KB
testcase_30 AC 233 ms
247,456 KB
testcase_31 AC 239 ms
246,832 KB
testcase_32 AC 239 ms
246,968 KB
testcase_33 AC 241 ms
247,232 KB
testcase_34 AC 244 ms
246,896 KB
testcase_35 AC 247 ms
248,184 KB
testcase_36 AC 240 ms
247,660 KB
testcase_37 AC 235 ms
247,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
R = 0
for i in range(1, M+1):
    R += (-1 if (M-i)%2 else 1) * (mul(cmb(M, i), power(i, N)))
    R %= mod
print(R)


0