結果

問題 No.1187 皇帝ペンギン
ユーザー yudedakoyudedako
提出日時 2020-08-27 09:42:40
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 333 ms / 1,000 ms
コード長 810 bytes
コンパイル時間 14,947 ms
コンパイル使用メモリ 414,448 KB
実行使用メモリ 69,364 KB
平均クエリ数 16.56
最終ジャッジ日時 2023-09-24 06:30:31
合計ジャッジ時間 35,751 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 333 ms
68,880 KB
testcase_01 AC 327 ms
68,468 KB
testcase_02 AC 328 ms
69,164 KB
testcase_03 AC 323 ms
69,084 KB
testcase_04 AC 318 ms
68,520 KB
testcase_05 AC 321 ms
68,904 KB
testcase_06 AC 321 ms
68,780 KB
testcase_07 AC 322 ms
69,096 KB
testcase_08 AC 323 ms
68,688 KB
testcase_09 AC 321 ms
69,184 KB
testcase_10 AC 325 ms
68,700 KB
testcase_11 AC 321 ms
69,280 KB
testcase_12 AC 325 ms
68,656 KB
testcase_13 AC 322 ms
68,924 KB
testcase_14 AC 318 ms
69,048 KB
testcase_15 AC 321 ms
68,480 KB
testcase_16 AC 316 ms
68,932 KB
testcase_17 AC 318 ms
69,068 KB
testcase_18 AC 319 ms
68,968 KB
testcase_19 AC 323 ms
68,972 KB
testcase_20 AC 325 ms
68,772 KB
testcase_21 AC 320 ms
68,844 KB
testcase_22 AC 319 ms
68,632 KB
testcase_23 AC 320 ms
69,032 KB
testcase_24 AC 318 ms
68,544 KB
testcase_25 AC 318 ms
68,804 KB
testcase_26 AC 320 ms
68,624 KB
testcase_27 AC 321 ms
69,160 KB
testcase_28 AC 322 ms
68,744 KB
testcase_29 AC 325 ms
68,792 KB
testcase_30 AC 323 ms
68,908 KB
testcase_31 AC 322 ms
68,984 KB
testcase_32 AC 321 ms
68,924 KB
testcase_33 AC 320 ms
68,864 KB
testcase_34 AC 327 ms
68,976 KB
testcase_35 AC 325 ms
68,816 KB
testcase_36 AC 321 ms
68,532 KB
testcase_37 AC 322 ms
68,632 KB
testcase_38 AC 318 ms
68,796 KB
testcase_39 AC 323 ms
68,628 KB
testcase_40 AC 323 ms
68,832 KB
testcase_41 AC 326 ms
68,532 KB
testcase_42 AC 325 ms
69,092 KB
testcase_43 AC 327 ms
68,864 KB
testcase_44 AC 322 ms
68,840 KB
testcase_45 AC 326 ms
69,364 KB
testcase_46 AC 321 ms
68,824 KB
testcase_47 AC 322 ms
69,056 KB
testcase_48 AC 323 ms
69,180 KB
testcase_49 AC 320 ms
68,952 KB
testcase_50 AC 323 ms
68,536 KB
testcase_51 AC 320 ms
68,632 KB
testcase_52 AC 322 ms
68,740 KB
testcase_53 AC 319 ms
68,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.lang.IllegalArgumentException


fun ask(value: Int): Response {
    println("? $value")
    return Response(readLine()!!)
}
sealed class Response{
    companion object {
        operator fun invoke(word: String): Response {
            return when(word.trim()) {
                "out" -> Out
                "safe" -> Safe
                else -> throw IllegalArgumentException()
            }
        }
    }
}
object Out : Response()
object Safe : Response()
fun main() {
    var min = 0
    var max = 1001
    while (min < max) {
        val mid = (min + max) shr 1
        when(ask(mid)) {
            Out -> when(ask(mid + 1)) {
                Out -> max = mid
                Safe -> min = mid + 1
            }
            Safe -> min = mid + 1
        }
    }
    println("! ${max - 1}")
}
0