結果

問題 No.1083 余りの余り
コンテスト
ユーザー yudedako
提出日時 2020-08-27 12:00:22
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 216 ms / 3,000 ms
コード長 545 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,541 ms
コンパイル使用メモリ 467,064 KB
実行使用メモリ 57,844 KB
最終ジャッジ日時 2026-05-07 23:09:06
合計ジャッジ時間 19,391 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import kotlin.math.max


fun calMax(m: Int, current: Int, currentMax: Int, mods: IntArray): Int {
    if (m == mods.lastIndex) {
        return max(currentMax, current % mods.last())
    }
    if (current < currentMax) return currentMax
    return calMax(m + 1, current, calMax(m + 1, current % mods[m], currentMax, mods), mods)
}

fun main() {
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val mods = readLine()!!.trim().split(' ').map(String::toInt).sortedDescending().toIntArray()
    println(calMax(0, k, 0, mods))
}
0