結果

問題 No.1286 Stone Skipping
ユーザー 👑 箱星箱星
提出日時 2020-09-08 08:32:44
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 13,484 ms
コンパイル使用メモリ 426,564 KB
実行使用メモリ 54,552 KB
最終ジャッジ日時 2023-09-30 16:01:22
合計ジャッジ時間 23,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
52,796 KB
testcase_01 AC 276 ms
52,616 KB
testcase_02 AC 271 ms
52,552 KB
testcase_03 AC 273 ms
53,020 KB
testcase_04 AC 273 ms
52,548 KB
testcase_05 AC 274 ms
52,588 KB
testcase_06 AC 276 ms
52,728 KB
testcase_07 AC 274 ms
52,740 KB
testcase_08 AC 272 ms
52,592 KB
testcase_09 AC 276 ms
52,680 KB
testcase_10 AC 275 ms
52,584 KB
testcase_11 AC 274 ms
54,552 KB
testcase_12 AC 279 ms
52,580 KB
testcase_13 AC 277 ms
52,668 KB
testcase_14 AC 278 ms
52,612 KB
testcase_15 AC 278 ms
52,984 KB
testcase_16 AC 288 ms
52,692 KB
testcase_17 AC 277 ms
52,600 KB
testcase_18 AC 273 ms
52,656 KB
testcase_19 AC 271 ms
52,580 KB
testcase_20 AC 272 ms
52,584 KB
testcase_21 AC 278 ms
52,888 KB
testcase_22 AC 272 ms
52,716 KB
testcase_23 AC 272 ms
52,708 KB
testcase_24 AC 271 ms
52,556 KB
testcase_25 AC 278 ms
52,696 KB
testcase_26 AC 279 ms
52,596 KB
testcase_27 AC 275 ms
52,772 KB
testcase_28 AC 273 ms
52,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val d = sc.nextLong()
    if (d !in 1..1000000000000000000) {
        throw Exception()
    }
    val set = mutableSetOf<Long>()
    for (num in 1..64) {
        var l = d / 2
        var r = d + 1
        while (r - l > 1) {
            val mid = (l + r) / 2
            val v = dist(mid, num)
            if (v <= d) {
                l = mid
            } else {
                r = mid
            }
        }
        if (dist(l, num) == d) {
            set.add(l)
        }
    }
    println(set.min())
}

fun dist(x:Long, num:Int):Long {
    var ret = 0L
    for (i in 0 until num) {
        ret += x.shr(i)
    }
    return ret
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    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()
    fun ready() = br.ready()
}
0