結果

問題 No.3011 あ、俺こいつの役やりたい!
ユーザー Torikun9971
提出日時 2025-02-01 19:28:45
言語 Kotlin
(2.1.0)
結果
RE  
実行時間 -
コード長 3,432 bytes
コンパイル時間 17,179 ms
コンパイル使用メモリ 495,140 KB
実行使用メモリ 77,088 KB
平均クエリ数 12.50
最終ジャッジ日時 2025-02-01 19:29:30
合計ジャッジ時間 40,138 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 RE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream
import java.io.PrintStream

fun main() {
    println((1..1_000_000_000).findN(30))
}

fun IntRange.findN(M: Int): Int {
    var min = this.start
    var max = this.last

    for (i in 0 until M - 1) {
        val mid = min + (max - min) / 2

        println(mid)
        val ans = readln().toInt()

        when (ans) {
            1 -> min = mid
            0 -> max = mid - 1
        }
    }

    return min
}

class FastReader(private val stream: InputStream = System.`in`) {
    private val buffer = ByteArray(1024 * 16)
    private var size = 0
    private var pos = 0
    private var isEnded = false

    private fun checkAndReplenishment() {
        if (isEnded || size > pos) return

        size = stream.read(buffer, 0, buffer.size)
        pos = 0
        if (size < 0) isEnded = true
    }

    fun readByte(): Byte {
        checkAndReplenishment()
        return buffer[pos++]
    }

    fun read(): String {
        val bytes = mutableListOf<Byte>()

        while (true) {
            val byte = readByte()

            if (byte == SPACE || byte == LINE_FEED) break
            bytes.add(byte)
        }

        return bytes.toByteArray().toString(Charsets.UTF_8)
    }

    fun readLine(): String {
        val bytes = mutableListOf<Byte>()

        while (true) {
            val byte = readByte()

            if (byte == LINE_FEED) break
            bytes.add(byte)
        }

        return bytes.toByteArray().toString(Charsets.UTF_8)
    }

    fun skip(i: Int = 1): FastReader {
        repeat(i) {
            while (readByte() != LINE_FEED) {}
        }

        return this
    }

    fun readChar(): Char = read()[0]
    fun readInt(): Int = read().toInt()
    fun readLong(): Long = read().toLong()
    fun readFloat(): Float = read().toFloat()
    fun readDouble(): Double = read().toDouble()
    fun readBoolean(): Boolean = read().toBoolean()
    fun readList(): List<String> = readLine().split(" ")
    fun readChars(): List<Char> = readLine().split(" ").map { it[0] }
    fun readInts(): List<Int> = readLine().split(" ").map { it.toInt() }
    fun readInts(adjust: Int): List<Int> = readLine().split(" ").map { it.toInt() + adjust }
    fun readLongs(): List<Long> = readLine().split(" ").map { it.toLong() }
    fun readLongs(adjust: Long): List<Long> = readLine().split(" ").map { it.toLong() + adjust }
    fun readFloats(): List<Float> = readLine().split(" ").map { it.toFloat() }
    fun readDoubles(): List<Double> = readLine().split(" ").map { it.toDouble() }
    fun readBooleans(): List<Boolean> = readLine().split(" ").map { it.toBoolean() }

    companion object {
        private const val SPACE = ' '.code.toByte()
        private const val LINE_FEED = '\n'.code.toByte()
    }
}

class FastWriter(private val stream: PrintStream = System.out, private val capacity: Int = 1024 * 1024 * 8) {
    private val writeText = StringBuilder()

    fun append(any: Any? = ""): FastWriter {
        writeText.append(any)
        checkCapacity()
        return this
    }

    fun appendLine(any: Any? = ""): FastWriter {
        writeText.appendLine(any)
        checkCapacity()
        return this
    }

    fun print() {
        stream.print(writeText)
        writeText.clear()
    }

    fun println() {
        stream.println(writeText)
        writeText.clear()
    }

    private fun checkCapacity() {
        if (writeText.length > capacity) print()
    }
}
0