結果

問題 No.1286 Stone Skipping
ユーザー da_louisda_louis
提出日時 2020-11-13 22:25:39
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 6,715 bytes
コンパイル時間 22,080 ms
コンパイル使用メモリ 449,584 KB
実行使用メモリ 57,004 KB
最終ジャッジ日時 2023-09-30 03:20:38
合計ジャッジ時間 29,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
52,636 KB
testcase_01 AC 289 ms
52,536 KB
testcase_02 AC 291 ms
54,652 KB
testcase_03 AC 288 ms
54,608 KB
testcase_04 AC 285 ms
53,068 KB
testcase_05 WA -
testcase_06 AC 285 ms
52,648 KB
testcase_07 AC 287 ms
52,804 KB
testcase_08 AC 293 ms
54,460 KB
testcase_09 AC 296 ms
54,524 KB
testcase_10 AC 292 ms
52,776 KB
testcase_11 AC 291 ms
52,520 KB
testcase_12 AC 290 ms
54,532 KB
testcase_13 AC 288 ms
54,548 KB
testcase_14 AC 297 ms
52,648 KB
testcase_15 WA -
testcase_16 AC 288 ms
52,584 KB
testcase_17 AC 292 ms
54,608 KB
testcase_18 AC 290 ms
54,760 KB
testcase_19 AC 295 ms
52,828 KB
testcase_20 AC 292 ms
52,712 KB
testcase_21 AC 290 ms
54,528 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 289 ms
54,512 KB
testcase_26 AC 295 ms
52,764 KB
testcase_27 AC 291 ms
54,720 KB
testcase_28 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:63:48: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    private fun Byte.isNumeric() = this in '0'.toByte()..'9'.toByte()
                                               ^
Main.kt:63:62: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    private fun Byte.isNumeric() = this in '0'.toByte()..'9'.toByte()
                                                             ^
Main.kt:64:68: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    private fun Byte.toNumVal() = if (this.isNumeric()) this - '0'.toByte() else error("$this is not numeric")
                                                                   ^
Main.kt:96:22: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b == '-'.toByte()) {
                     ^
Main.kt:121:22: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b == '-'.toByte()) {
                     ^
Main.kt:127:22: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b == '.'.toByte()) {
                     ^

ソースコード

diff #

import java.math.BigInteger

fun main() = contest274b()

@OptIn(ExperimentalStdlibApi::class)
fun contest274b() = Messiah_contest274b().exec {
    val d = readLong()

    fun calcD(initialVelocity: BigInteger): BigInteger {
        var D = BigInteger.ZERO
        var currVelocity = initialVelocity
        while (currVelocity > BigInteger.ZERO) {
            D += currVelocity
            currVelocity /= BigInteger.TWO
        }
        return D
    }

    // 飛距離 D 以上にする最小値
    fun lowerBound(key: Long): BigInteger {
        var ng = (-1).toBigInteger()
        var ok = Long.MAX_VALUE.toBigInteger()

        while ((ok - ng).abs() > BigInteger.ONE) {
            val mid = (ok + ng) / BigInteger.TWO
            if (calcD(mid) >= key.toBigInteger()) ok = mid else ng = mid
        }
        return ok
    }

    val lowerBound = lowerBound(d)

    fun distances(initialVelocity: BigInteger): Set<BigInteger> {
        val distances = mutableSetOf<BigInteger>()
        var D = BigInteger.ZERO
        var currVelocity = initialVelocity
        while (currVelocity > BigInteger.ZERO) {
            D += currVelocity
            distances += D
            currVelocity /= BigInteger.TWO
        }
        return distances
    }

    val distances = distances(lowerBound)
    val answer = distances.let { if (d.toBigInteger() in it) lowerBound else d.toBigInteger() }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("MemberVisibilityCanBePrivate", "ClassName", "FunctionName", "PropertyName", "unused")
private class Messiah_contest274b(private val separator: String = System.lineSeparator()) {
    //////////////////////////////////////////////////
    // IO
    //////////////////////////////////////////////////
    private val input = System.`in`
    private val buffer = ByteArray(1024)
    private var pointer = 0
    private var bufferLength = 0
    private val sb = StringBuilder()
    private fun Byte.isPrintable() = this in 33..126
    private fun Byte.isNumeric() = this in '0'.toByte()..'9'.toByte()
    private fun Byte.toNumVal() = if (this.isNumeric()) this - '0'.toByte() else error("$this is not numeric")
    private val enableDebugMode = "ENABLE_DEBUG_MODE_FOR_COMPETITIVE_PROGRAMING" in System.getenv()

    private fun hasNextByte(): Boolean {
        return if (pointer < bufferLength) true else {
            pointer = 0
            bufferLength = input.read(buffer)
            bufferLength > 0
        }
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[pointer++] else -1
    private fun skipUnprintable() = run { while (hasNextByte() && !buffer[pointer].isPrintable()) pointer++ }
    private fun hasNext(): Boolean = run { skipUnprintable() }.run { hasNextByte() }
    private fun hasNextOrError() = if (!hasNext()) error("has no next element.") else Unit

    fun readString(): String {
        hasNextOrError()
        val sb = StringBuilder()
        var b = readByte()
        while (b.isPrintable()) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun readLong(): Long {
        hasNextOrError()
        var n = 0L
        var negative = false
        var b = readByte()
        if (b == '-'.toByte()) {
            negative = true
            b = readByte()
        }
        if (!b.isNumeric()) error("$b is not numeric.")
        while (true) {
            when {
                b.isNumeric() -> n = n * 10 + b.toNumVal()
                b.toInt() == -1 || !b.isPrintable() -> return if (negative) -n else n
                else -> error("failed to parse. [n=$n, b=$b]")
            }
            b = readByte()
        }
    }

    fun readInt() = readLong()
        .let { if (it in Int.MIN_VALUE..Int.MAX_VALUE) it.toInt() else error("$it is not in range of Int.") }

    fun readIntAsIndex() = readInt().dec()

    fun readDouble(): Double {
        var n = 0.0
        var div = 1.0
        var negative = false
        var b = readByte()
        if (b == '-'.toByte()) {
            negative = true
            b = readByte()
        }
        do n = n * 10 + b.toNumVal()
        while (run { b = readByte() }.run { b.isNumeric() })
        if (b == '.'.toByte()) {
            while (run { b = readByte() }.run { b.isNumeric() })
                n += b.toNumVal() / (run { div *= 10 }.run { div })
        }
        return if (negative) -n else n
    }

    fun readString(size: Int): Array<String> = Array(size) { readString() }
    fun readChars2D(height: Int): Array<CharArray> = Array(height) { readString().toCharArray() }
    fun readLong(size: Int): LongArray = LongArray(size) { readLong() }
    fun readLong2D(height: Int, width: Int): Array<LongArray> = Array(height) { LongArray(width) { readLong() } }
    fun readInt(size: Int): IntArray = IntArray(size) { readInt() }
    fun readInt2D(height: Int, width: Int): Array<IntArray> = Array(height) { IntArray(width) { readInt() } }
    fun readIntAsIndex(size: Int): IntArray = IntArray(size) { readIntAsIndex() }
    fun readIntAsIndex2D(height: Int, width: Int): Array<IntArray> =
        Array(height) { IntArray(width) { readIntAsIndex() } }

    fun readDouble(size: Int): DoubleArray = DoubleArray(size) { readDouble() }

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any.toString()) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }
    fun flush() = run { kotlin.io.println(sb); sb.clear() }
    fun debug(any: Any): Unit = run { if (enableDebugMode) System.err.println(any) }
    fun debug(action: () -> Unit): Unit = run { if (enableDebugMode) action() }

    fun exec(action: Messiah_contest274b.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")

    //////////////////////////////////////////////////
    // Misc
    //////////////////////////////////////////////////
    /**
     * `[index] in [this]` is sugar syntax of `index in 0 until [this]`.
     */
    operator fun Int.contains(index: Int) = index in this.indices()

    /**
     * `[this].indices()` is sugar syntax of `0 until [this]`.
     */
    fun Int.indices() = 0 until this

    fun YesNo(b: Boolean): String = if (b) Yes else No
    val Yes = "Yes"
    val No = "No"
    fun YES_NO(b: Boolean): String = if (b) YES else NO
    val YES = "YES"
    val NO = "NO"
}
// endregion kokomade template dayo (^o^)
0