結果

問題 No.1286 Stone Skipping
ユーザー 👑 箱
提出日時 2020-08-17 19:29:45
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 15,060 ms
コンパイル使用メモリ 446,372 KB
実行使用メモリ 50,920 KB
最終ジャッジ日時 2024-04-28 19:09:13
合計ジャッジ時間 24,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
50,692 KB
testcase_01 AC 307 ms
50,780 KB
testcase_02 AC 305 ms
50,852 KB
testcase_03 AC 314 ms
50,748 KB
testcase_04 AC 319 ms
50,756 KB
testcase_05 AC 307 ms
50,772 KB
testcase_06 AC 309 ms
50,672 KB
testcase_07 AC 315 ms
50,464 KB
testcase_08 AC 310 ms
50,912 KB
testcase_09 AC 318 ms
50,656 KB
testcase_10 AC 314 ms
50,532 KB
testcase_11 AC 315 ms
50,484 KB
testcase_12 AC 309 ms
50,636 KB
testcase_13 AC 314 ms
50,616 KB
testcase_14 AC 315 ms
50,584 KB
testcase_15 AC 315 ms
50,644 KB
testcase_16 AC 314 ms
50,596 KB
testcase_17 AC 316 ms
50,712 KB
testcase_18 AC 313 ms
50,920 KB
testcase_19 AC 317 ms
50,780 KB
testcase_20 AC 306 ms
50,560 KB
testcase_21 AC 315 ms
50,764 KB
testcase_22 AC 312 ms
50,656 KB
testcase_23 AC 314 ms
50,656 KB
testcase_24 AC 318 ms
50,684 KB
testcase_25 AC 319 ms
50,652 KB
testcase_26 AC 314 ms
50,812 KB
testcase_27 AC 319 ms
50,604 KB
testcase_28 AC 313 ms
50,744 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()
    val set = mutableSetOf<Long>()
    for (num in 1..64) {
        var l = 1L
        var r = 1000000000000000001L
        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.minOrNull())
}

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