結果

問題 No.1083 余りの余り
ユーザー yudedako
提出日時 2020-08-27 12:00:22
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 361 ms / 3,000 ms
コード長 545 bytes
コンパイル時間 12,781 ms
コンパイル使用メモリ 432,024 KB
実行使用メモリ 55,412 KB
最終ジャッジ日時 2024-11-07 15:36:51
合計ジャッジ時間 26,117 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:13:10: warning: variable 'n' is never used
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
         ^

ソースコード

diff #

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