結果

問題 No.253 ロウソクの長さ
ユーザー くわいくわい
提出日時 2015-10-24 13:36:08
言語 Scala(Beta)
(3.4.0)
結果
RE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 12,132 ms
コンパイル使用メモリ 239,416 KB
実行使用メモリ 76,208 KB
平均クエリ数 36.94
最終ジャッジ日時 2023-09-23 08:04:02
合計ジャッジ時間 43,710 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 823 ms
75,072 KB
testcase_01 AC 826 ms
75,844 KB
testcase_02 AC 863 ms
76,052 KB
testcase_03 AC 845 ms
75,564 KB
testcase_04 AC 865 ms
75,824 KB
testcase_05 AC 863 ms
75,368 KB
testcase_06 AC 844 ms
74,748 KB
testcase_07 AC 845 ms
75,904 KB
testcase_08 AC 831 ms
75,448 KB
testcase_09 AC 823 ms
75,372 KB
testcase_10 AC 842 ms
75,504 KB
testcase_11 AC 854 ms
75,768 KB
testcase_12 AC 839 ms
75,168 KB
testcase_13 AC 843 ms
75,676 KB
testcase_14 AC 836 ms
75,976 KB
testcase_15 AC 852 ms
75,744 KB
testcase_16 AC 838 ms
76,100 KB
testcase_17 RE -
testcase_18 AC 839 ms
76,008 KB
testcase_19 AC 829 ms
75,824 KB
testcase_20 AC 823 ms
76,016 KB
testcase_21 AC 835 ms
75,836 KB
testcase_22 AC 823 ms
75,656 KB
testcase_23 AC 834 ms
75,588 KB
testcase_24 AC 842 ms
76,068 KB
testcase_25 AC 835 ms
76,004 KB
testcase_26 AC 825 ms
75,568 KB
testcase_27 AC 825 ms
75,576 KB
testcase_28 AC 822 ms
75,488 KB
testcase_29 AC 822 ms
75,424 KB
testcase_30 AC 821 ms
76,200 KB
testcase_31 AC 807 ms
75,884 KB
testcase_32 AC 811 ms
75,200 KB
testcase_33 AC 841 ms
76,208 KB
testcase_34 AC 833 ms
76,088 KB
testcase_35 AC 817 ms
75,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.annotation.tailrec
import scala.io.StdIn

object Problem253 {

  def question(len: Int): Int = {
    println("? " + len)
    StdIn.readInt()
  }

  def answer(len: Int): Unit = {
    println("! " + len)
  }

  def waitBurnout(): Int = (1 until 100).find(x => question(0) == 0).get

  def search(): Int = {
    @tailrec
    def searchR(min: Int, max: Int, burned: Int): Int = {
      val mid = (min + max) / 2

      question(mid) match {
        case 1 => searchR(mid - 1, max - 1, burned + 1)
        case 0 => mid + burned
        case -1 => searchR(min - 1, mid - 1, burned + 1)
      }
    }

    val min = 100
    val max = Math.pow(10, 9).toInt
    searchR(min, max, 1)
  }

  def proc(): Int = {
    if (question(101) != -1) {
      // 101以上は二分探索
      search()
    } else {
      // 0以下の処理が面倒なので長さが100以下の場合は燃え尽きるまで待つ
      waitBurnout()
    }
  }

  def main(args: Array[String]): Unit = {
    val result = proc()
    answer(result)
  }
}
0