結果

問題 No.253 ロウソクの長さ
ユーザー jitomeskyjitomesky
提出日時 2015-08-01 18:09:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 24,720 KB
平均クエリ数 31.06
最終ジャッジ日時 2023-09-23 05:33:53
合計ジャッジ時間 7,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
24,320 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 42 ms
24,104 KB
testcase_11 WA -
testcase_12 AC 46 ms
24,160 KB
testcase_13 AC 45 ms
24,096 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 43 ms
24,332 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 42 ms
24,392 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 43 ms
24,632 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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
        max_num = max_num if max_num >= 0 else 0
        min_num = min_num if min_num >= 0 else 0
        judge = int((max_num - min_num) / 2) + min_num
    return i, min_num

def second_step(i, judge):
    for i in range(i, 100):
        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)

# 答えを出力
result(r)

0