結果

問題 No.1035 Color Box
ユーザー brthyyjpbrthyyjp
提出日時 2020-04-25 12:18:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 246,400 KB
最終ジャッジ日時 2024-04-24 14:12:32
合計ジャッジ時間 15,545 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 460 ms
246,016 KB
testcase_01 AC 348 ms
246,144 KB
testcase_02 AC 336 ms
246,016 KB
testcase_03 AC 394 ms
246,272 KB
testcase_04 AC 386 ms
246,272 KB
testcase_05 AC 346 ms
246,016 KB
testcase_06 AC 339 ms
246,144 KB
testcase_07 AC 348 ms
246,016 KB
testcase_08 AC 450 ms
246,272 KB
testcase_09 AC 398 ms
246,272 KB
testcase_10 AC 334 ms
246,016 KB
testcase_11 AC 345 ms
246,400 KB
testcase_12 AC 336 ms
246,016 KB
testcase_13 AC 437 ms
246,016 KB
testcase_14 AC 447 ms
246,016 KB
testcase_15 AC 469 ms
246,144 KB
testcase_16 AC 333 ms
245,888 KB
testcase_17 AC 323 ms
245,888 KB
testcase_18 AC 325 ms
246,272 KB
testcase_19 AC 455 ms
245,888 KB
testcase_20 AC 332 ms
245,888 KB
testcase_21 AC 334 ms
246,272 KB
testcase_22 AC 331 ms
246,016 KB
testcase_23 AC 331 ms
246,144 KB
testcase_24 AC 340 ms
246,016 KB
testcase_25 AC 338 ms
246,400 KB
testcase_26 AC 327 ms
246,144 KB
testcase_27 AC 332 ms
246,272 KB
testcase_28 AC 331 ms
246,144 KB
testcase_29 AC 334 ms
245,888 KB
testcase_30 AC 336 ms
246,272 KB
testcase_31 AC 328 ms
245,888 KB
testcase_32 AC 329 ms
246,016 KB
testcase_33 AC 332 ms
246,272 KB
testcase_34 AC 353 ms
245,888 KB
testcase_35 AC 341 ms
246,016 KB
testcase_36 AC 330 ms
246,272 KB
testcase_37 AC 331 ms
246,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
mod = 10**9*7

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

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

def power(a, n, mod):
  bi=str(format(n,"b")) #2進数
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res

res = 0
for i in range(m+1):
    temp = cmb1(m, i, mod) * power(i, n, mod)
    if (m-i)%2 == 0:
        res += temp
    else:
        res -= temp
print(res%mod)
0