結果

問題 No.253 ロウソクの長さ
コンテスト
ユーザー latte0119
提出日時 2015-08-06 12:41:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 601 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 890 ms
コンパイル使用メモリ 173,704 KB
実行使用メモリ 28,720 KB
平均クエリ数 22.08
最終ジャッジ日時 2026-03-31 10:25:26
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int ask(int Y){
    printf("? %d\n",Y);
    fflush(stdout);
    int res;
    scanf("%d",&res);
    return res;
}

int main(){
    int ub,lb,cnt=1;
    if(ask(100)==-1){
        ub=100;
        lb=0;
    }
    else{
        ub=1e9;
        lb=0;
    }

    while(ub-lb>1){

        int mid=(ub+lb)/2;
        int r=ask(mid);
        if(r==1)lb=mid;
        else if(r==-1)ub=mid;
        else{
            printf("! %d\n",mid+cnt);
            fflush(stdout);
            return 0;
        }
        cnt++;
        ub--;
        lb--;
    }
    return 0;
}
0