結果

問題 No.91 赤、緑、青の石
ユーザー バカらっくバカらっく
提出日時 2019-09-28 04:52:16
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 332 ms / 5,000 ms
コード長 1,147 bytes
コンパイル時間 13,787 ms
コンパイル使用メモリ 420,448 KB
実行使用メモリ 58,432 KB
最終ジャッジ日時 2023-09-06 12:44:30
合計ジャッジ時間 25,570 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
57,124 KB
testcase_01 AC 307 ms
56,936 KB
testcase_02 AC 305 ms
57,372 KB
testcase_03 AC 305 ms
57,104 KB
testcase_04 AC 306 ms
57,476 KB
testcase_05 AC 305 ms
57,316 KB
testcase_06 AC 305 ms
57,304 KB
testcase_07 AC 306 ms
57,044 KB
testcase_08 AC 305 ms
57,020 KB
testcase_09 AC 304 ms
57,052 KB
testcase_10 AC 308 ms
57,084 KB
testcase_11 AC 307 ms
57,448 KB
testcase_12 AC 307 ms
57,072 KB
testcase_13 AC 304 ms
57,048 KB
testcase_14 AC 307 ms
56,928 KB
testcase_15 AC 309 ms
57,304 KB
testcase_16 AC 322 ms
57,068 KB
testcase_17 AC 308 ms
57,040 KB
testcase_18 AC 306 ms
57,064 KB
testcase_19 AC 308 ms
58,432 KB
testcase_20 AC 304 ms
57,072 KB
testcase_21 AC 307 ms
56,924 KB
testcase_22 AC 305 ms
57,152 KB
testcase_23 AC 332 ms
57,052 KB
testcase_24 AC 312 ms
56,912 KB
testcase_25 AC 314 ms
57,052 KB
testcase_26 AC 309 ms
57,120 KB
testcase_27 AC 307 ms
57,312 KB
testcase_28 AC 320 ms
57,352 KB
testcase_29 AC 323 ms
56,944 KB
testcase_30 AC 309 ms
57,052 KB
testcase_31 AC 326 ms
57,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

import kotlin.math.PI


fun main(arr:Array<String>) {
    rgb = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val ans = getAns(rgb[0], rgb[2])
    println(ans)
}

var rgb = listOf<Int>()

fun getAns(min:Int, max:Int):Int {
    if(max-min <= 1) {
        if(canCreate(max)) {
            return max
        }
        return min
    }

    val mid = (max+min)/2
    return if(canCreate(mid)) {
        getAns(mid, max)
    } else {
        getAns(min, mid)
    }
}

fun canCreate(count:Int):Boolean {
    if(count*3 > rgb.sum()) {
        return false
    }
    if(count <= rgb[0]) {
        return true
    }
    val diff = rgb.map { it - count }.toMutableList()
    if(diff[0] < 0) {
        val move = Math.min(diff[0] * -1, diff[2] / 2)
        diff[0] += move
        diff[2] -= move*2
        if(diff[0] < 0 && diff[1] > 0) {
            val move2 = Math.min(diff[0] * -1, diff[1] / 2)
            diff[0] += move2
            diff[1] -= move2 * 2
        }
    }
    if(diff[1] < 0) {
        val move = Math.min(diff[1] * -1, diff[2] / 2)
        diff[1] += move
        diff[2] -= move * 2
    }

    return diff.all { it >= 0 }
}
0