結果

問題 No.2791 Beginner Contest
ユーザー 👑 箱星箱星
提出日時 2023-12-22 04:52:01
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 12,405 ms
コンパイル使用メモリ 442,444 KB
実行使用メモリ 63,080 KB
最終ジャッジ日時 2024-06-21 20:51:02
合計ジャッジ時間 17,992 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 273 ms
58,444 KB
testcase_01 AC 274 ms
58,552 KB
testcase_02 AC 286 ms
58,544 KB
testcase_03 AC 269 ms
58,372 KB
testcase_04 AC 268 ms
58,480 KB
testcase_05 AC 272 ms
58,476 KB
testcase_06 AC 296 ms
61,028 KB
testcase_07 AC 274 ms
58,480 KB
testcase_08 AC 272 ms
58,592 KB
testcase_09 AC 283 ms
62,952 KB
testcase_10 AC 288 ms
63,068 KB
testcase_11 AC 287 ms
58,680 KB
testcase_12 AC 294 ms
63,080 KB
testcase_13 AC 280 ms
58,712 KB
testcase_14 AC 273 ms
58,556 KB
testcase_15 AC 291 ms
58,676 KB
testcase_16 AC 278 ms
58,364 KB
testcase_17 AC 266 ms
58,536 KB
testcase_18 AC 289 ms
58,628 KB
testcase_19 AC 297 ms
58,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val k = nextInt()
    val dp = Array(n + 1) { 1L }
    val mod = 998244353L
    for (i in 1..n) {
        dp[i] = dp[i - 1] + if (i >= k) dp[i - k] else 0
        dp[i] %= mod
    }
    println(dp[n])
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0