import java.util.Scanner import scala.annotation.tailrec object Problem253 { val sc = new Scanner(System.in) def question(len: Int): Int = { println("? " + len) sc.nextInt() } def answer(len: Int): Unit = { println("! " + len) } def waitBurnout() = while (question(0) != 0) {} def search(): Int = { @tailrec def searchR(min: Int, max: Int): Int = { val mid = (min + max) / 2 question(mid) match { case 1 => searchR(mid - 1, max - 1) case 0 => mid - 1 case -1 => searchR(min - 1, mid - 1) } } val min = 100 val max = Math.pow(10, 9).toInt searchR(min, max) } def main(args: Array[String]): Unit = { if (question(101) != -1) { val result = search() answer(result) } else { // 0以下の処理が面倒なので長さが100以下の場合は燃え尽きるまで待つ waitBurnout() answer(0) } } }