結果
問題 | No.253 ロウソクの長さ |
ユーザー | くわい |
提出日時 | 2015-10-24 13:50:10 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 826 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 13,794 ms |
コンパイル使用メモリ | 247,396 KB |
実行使用メモリ | 76,712 KB |
平均クエリ数 | 28.69 |
最終ジャッジ日時 | 2023-09-23 21:57:12 |
合計ジャッジ時間 | 44,306 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 785 ms
75,424 KB |
testcase_01 | AC | 780 ms
75,596 KB |
testcase_02 | AC | 750 ms
75,904 KB |
testcase_03 | AC | 785 ms
75,152 KB |
testcase_04 | AC | 750 ms
75,732 KB |
testcase_05 | AC | 751 ms
76,712 KB |
testcase_06 | AC | 761 ms
76,492 KB |
testcase_07 | AC | 747 ms
75,672 KB |
testcase_08 | AC | 753 ms
75,264 KB |
testcase_09 | AC | 749 ms
75,336 KB |
testcase_10 | AC | 758 ms
76,272 KB |
testcase_11 | AC | 765 ms
75,296 KB |
testcase_12 | AC | 826 ms
76,064 KB |
testcase_13 | AC | 782 ms
75,692 KB |
testcase_14 | AC | 777 ms
75,212 KB |
testcase_15 | AC | 773 ms
75,596 KB |
testcase_16 | AC | 791 ms
75,984 KB |
testcase_17 | AC | 743 ms
75,252 KB |
testcase_18 | AC | 775 ms
75,040 KB |
testcase_19 | AC | 764 ms
75,264 KB |
testcase_20 | AC | 758 ms
76,032 KB |
testcase_21 | AC | 755 ms
74,920 KB |
testcase_22 | AC | 779 ms
75,552 KB |
testcase_23 | AC | 767 ms
76,384 KB |
testcase_24 | AC | 751 ms
75,608 KB |
testcase_25 | AC | 772 ms
75,720 KB |
testcase_26 | AC | 781 ms
75,832 KB |
testcase_27 | AC | 770 ms
76,252 KB |
testcase_28 | AC | 764 ms
76,008 KB |
testcase_29 | AC | 771 ms
76,044 KB |
testcase_30 | AC | 775 ms
75,720 KB |
testcase_31 | AC | 759 ms
75,600 KB |
testcase_32 | AC | 757 ms
75,300 KB |
testcase_33 | AC | 788 ms
75,416 KB |
testcase_34 | AC | 777 ms
76,104 KB |
testcase_35 | AC | 777 ms
75,684 KB |
ソースコード
import scala.annotation.tailrec import scala.io.StdIn object Problem253 { val threshold: Int = 50 def question(len: Int): Int = { println("? " + len) StdIn.readInt() } def answer(len: Int): Unit = { println("! " + len) } def waitBurnout(): Int = (1 to threshold + 1).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 = threshold val max = Math.pow(10, 9).toInt searchR(min, max, 1) } def proc(): Int = { question(threshold) match { case 1 => search() // 二分探索 case 0 => threshold // 一回で当たった case -1 => waitBurnout() // 0以下の処理が面倒なので長さが閾値以下の場合は燃え尽きるまで待つ } } def main(args: Array[String]): Unit = { val result = proc() answer(result) } }