結果

問題 No.1102 Remnants
ユーザー FromBooskaFromBooska
提出日時 2023-03-22 17:48:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 915 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 53,556 KB
最終ジャッジ日時 2023-10-18 19:03:30
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,556 KB
testcase_01 AC 36 ms
53,384 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 寄与数をどうやって求めるのかわからず
# 公式解説より
# K回の操作、各回の(l, r)を(li, ri)とすれば
# 1 <= l1 <= l2 <= ---- lK <= rK <= ---- <= r1 <= N
# あるAi項がK回後に残っているには lK <= i <= rK
# 左側は nCk(i+K-1, K)
# 右側は nCk(N-i+K, K)
# その積が寄与分となる

mod = 10**9+7
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
# nCrメモ化パッケージ
factorial = [1] #0分
inverse = [1] #0分
for i in range(1, N+K+1):
    factorial.append(factorial[-1]*i%mod)
    inverse.append(pow(factorial[-1], mod-2, mod))
    
def nCr_fast(N, R, MOD):
    if N < R or R < 0:
        return 0
    elif R == 0 or R == N:
        return 1
    return factorial[N]*inverse[R]*inverse[N-R]%MOD

ans = 0
for i in range(N):
    count = nCr_fast(i+K, K, mod) * nCr_fast(N-1-i+K, K, mod)
    ans += count*A[i]
    ans %= mod
print(ans)
0