結果

問題 No.2754 Cumulate and Drop
ユーザー rlangevinrlangevin
提出日時 2024-05-10 21:54:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 112,540 KB
最終ジャッジ日時 2024-05-10 21:54:29
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
67,140 KB
testcase_01 AC 56 ms
66,940 KB
testcase_02 AC 53 ms
66,800 KB
testcase_03 AC 58 ms
67,820 KB
testcase_04 AC 52 ms
67,332 KB
testcase_05 AC 51 ms
68,168 KB
testcase_06 AC 51 ms
68,148 KB
testcase_07 AC 50 ms
67,540 KB
testcase_08 AC 117 ms
90,232 KB
testcase_09 AC 270 ms
108,144 KB
testcase_10 AC 279 ms
111,756 KB
testcase_11 AC 220 ms
104,756 KB
testcase_12 AC 350 ms
112,116 KB
testcase_13 AC 302 ms
112,276 KB
testcase_14 AC 323 ms
112,232 KB
testcase_15 AC 206 ms
102,644 KB
testcase_16 AC 102 ms
88,400 KB
testcase_17 AC 381 ms
112,424 KB
testcase_18 AC 333 ms
112,540 KB
testcase_19 AC 329 ms
112,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))

mod = 998244353
n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod

    
ans = []
for k in range(N - 1):
    ans.append((N - k) * comb(N - 1 + k, k) * pow(N, mod - 2, mod) % mod)
ans.append(ans[-1])
ans.reverse()
v = 0
for i in range(N):
    v += ans[i] * A[i]
    v %= mod 
print(v)
0