結果
| 問題 |
No.2754 Cumulate and Drop
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-05-13 01:15:55 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,268 bytes |
| コンパイル時間 | 19,361 ms |
| コンパイル使用メモリ | 438,880 KB |
| 実行使用メモリ | 102,812 KB |
| 最終ジャッジ日時 | 2024-12-20 09:20:41 |
| 合計ジャッジ時間 | 28,954 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 2 |
ソースコード
fun main() {
val n = readLine()!!.toInt()
val a = readLine()!!.split(" ").map { it.toLong() }
val mod = 998244353L
val fact = LongArray(500000) { 1L }
for (i in 1 until fact.size) {
fact[i] = fact[i - 1] * i % mod
}
val factInv = LongArray(fact.size) { i ->
if (i == fact.lastIndex) fact.last().modPow(mod - 2, mod)
else 0L
}
for (i in fact.lastIndex - 1 downTo 0) {
factInv[i] = factInv[i + 1] * (i + 1) % mod
}
fun combi(a: Int, b: Int): Long {
return if (b in 0..a) {
fact[a] * factInv[b] % mod * factInv[a - b] % mod
} else {
0L
}
}
fun cat(i: Int, j: Int): Long {
return (combi(i + j + 1, j) - 2 * combi(i + j, j - 1) + mod) % mod
}
var ans = 0L
a.reversed().forEachIndexed { i, ai ->
ans = (ans + ai.toLong() * cat(n - 1, i) % mod) % mod
}
println(ans)
}
private fun Long.modPow(exponent: Long, modulus: Long): Long {
var result = 1L
var exp = exponent
var base = this % modulus
while (exp > 0) {
if (exp and 1 == 1L) {
result = result * base % modulus
}
base = base * base % modulus
exp = exp shr 1
}
return result
}
titia