結果

問題 No.253 ロウソクの長さ
ユーザー くわいくわい
提出日時 2015-10-24 13:38:01
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 9,089 ms
コンパイル使用メモリ 250,564 KB
実行使用メモリ 76,744 KB
平均クエリ数 30.11
最終ジャッジ日時 2023-09-23 08:03:16
合計ジャッジ時間 43,176 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 864 ms
75,300 KB
testcase_01 AC 861 ms
76,072 KB
testcase_02 AC 855 ms
74,768 KB
testcase_03 AC 868 ms
75,132 KB
testcase_04 AC 847 ms
75,340 KB
testcase_05 AC 827 ms
75,692 KB
testcase_06 AC 831 ms
75,636 KB
testcase_07 AC 828 ms
75,332 KB
testcase_08 AC 855 ms
75,800 KB
testcase_09 AC 846 ms
75,732 KB
testcase_10 AC 835 ms
76,116 KB
testcase_11 AC 857 ms
75,500 KB
testcase_12 AC 825 ms
75,360 KB
testcase_13 AC 856 ms
74,512 KB
testcase_14 AC 855 ms
75,664 KB
testcase_15 AC 845 ms
74,800 KB
testcase_16 AC 864 ms
75,392 KB
testcase_17 AC 856 ms
75,084 KB
testcase_18 AC 849 ms
75,296 KB
testcase_19 AC 866 ms
75,480 KB
testcase_20 AC 857 ms
75,124 KB
testcase_21 WA -
testcase_22 AC 875 ms
76,168 KB
testcase_23 AC 864 ms
75,672 KB
testcase_24 AC 860 ms
75,432 KB
testcase_25 AC 867 ms
75,768 KB
testcase_26 AC 867 ms
76,232 KB
testcase_27 AC 848 ms
74,496 KB
testcase_28 AC 840 ms
76,176 KB
testcase_29 AC 838 ms
76,744 KB
testcase_30 AC 826 ms
75,700 KB
testcase_31 AC 851 ms
75,032 KB
testcase_32 AC 841 ms
75,324 KB
testcase_33 AC 862 ms
76,132 KB
testcase_34 AC 861 ms
76,032 KB
testcase_35 AC 861 ms
75,684 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 to 50).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 = 50
    val max = Math.pow(10, 9).toInt
    searchR(min, max, 1)
  }

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

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