結果

問題 No.253 ロウソクの長さ
ユーザー jitomeskyjitomesky
提出日時 2015-08-01 18:18:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 24,764 KB
平均クエリ数 18.83
最終ジャッジ日時 2023-09-23 05:35:23
合計ジャッジ時間 7,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
24,264 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 41 ms
24,292 KB
testcase_11 RE -
testcase_12 AC 41 ms
24,660 KB
testcase_13 AC 41 ms
24,424 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 40 ms
24,000 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 41 ms
23,900 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 41 ms
24,460 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 41 ms
24,356 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def question(num):
    print("? %d" % num)
    sys.stdout.flush()
    n = int(input())
    return n

def result(num):
    print("! %d" % num)
    sys.stdout.flush()

def first_step(i, max_num, min_num):
    judge = int(max_num / 2)
    
    for i in range(i, 29):
        r = question(judge)
        if r == 1:
            # higer
            min_num = judge
        elif r == -1:
            # low
            max_num = judge
        else:
            return 1000, (judge+i)
        max_num -= 1
        min_num -= 1
        judge = int((max_num - min_num) / 2) + min_num
    return i, min_num

def second_step(i, judge):
    for i in range(i, 100 - i):
        print(i)
        r = question(judge)
        if r == 0:
            break
    return i


# main
max_num = 1e9
judge = int(max_num / 2)
min_num = 10

# less than 100?
r = question(100)
max_num -= 1
min_num -= 1

if r == -1:
    r = second_step(1, min_num)
elif r == 1:
    min_num = 100 - 1
    i, min_num = first_step(1, max_num, min_num)
    if i > 100:
        r = min_num
    else:
        r = second_step(i, min_num)
else:
    r = 100

# 答えを出力
result(r)
0