結果

問題 No.1286 Stone Skipping
ユーザー yudedakoyudedako
提出日時 2022-01-10 16:50:12
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 12,340 ms
コンパイル使用メモリ 433,920 KB
実行使用メモリ 51,136 KB
最終ジャッジ日時 2024-04-26 20:10:33
合計ジャッジ時間 22,170 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
50,780 KB
testcase_01 AC 283 ms
50,984 KB
testcase_02 AC 282 ms
50,940 KB
testcase_03 AC 283 ms
51,004 KB
testcase_04 AC 286 ms
51,104 KB
testcase_05 AC 285 ms
50,948 KB
testcase_06 AC 282 ms
50,992 KB
testcase_07 AC 269 ms
50,824 KB
testcase_08 AC 284 ms
50,956 KB
testcase_09 AC 290 ms
50,976 KB
testcase_10 AC 279 ms
50,948 KB
testcase_11 AC 279 ms
50,928 KB
testcase_12 AC 278 ms
50,940 KB
testcase_13 AC 277 ms
50,884 KB
testcase_14 AC 274 ms
51,012 KB
testcase_15 AC 283 ms
51,008 KB
testcase_16 AC 286 ms
50,924 KB
testcase_17 AC 279 ms
50,872 KB
testcase_18 AC 286 ms
50,976 KB
testcase_19 AC 282 ms
50,880 KB
testcase_20 AC 281 ms
51,136 KB
testcase_21 AC 286 ms
50,704 KB
testcase_22 AC 278 ms
50,844 KB
testcase_23 AC 282 ms
50,904 KB
testcase_24 AC 273 ms
51,080 KB
testcase_25 AC 282 ms
50,948 KB
testcase_26 AC 287 ms
50,884 KB
testcase_27 AC 275 ms
50,936 KB
testcase_28 AC 290 ms
51,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val distance = readLine()!!.trim().toLong()
    var result = distance
    fun sumDistance(step: Int, d: Long): Long {
        var sum = 0L
        var dist = d
        repeat(step) {
            sum += dist
            dist /= 2
        }
        return sum
    }
    for (step in 2 .. 60) {
        var min = 0L
        var max = distance
        while (min < max) {
            val mid = (min + max) / 2
            val sum = sumDistance(step, mid)
            if (sum < distance) {
                min = mid + 1
            }else {
                max = mid
            }
        }
        if (sumDistance(step, max) == distance) {
            result = minOf(result, max)
        }
    }
    println(result)
}
0