結果

問題 No.253 ロウソクの長さ
ユーザー imulanimulan
提出日時 2016-10-09 23:26:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,312 ms
コンパイル使用メモリ 164,732 KB
実行使用メモリ 24,312 KB
平均クエリ数 32.17
最終ジャッジ日時 2023-09-24 00:36:13
合計ジャッジ時間 4,019 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,964 KB
testcase_01 AC 26 ms
24,276 KB
testcase_02 AC 24 ms
23,592 KB
testcase_03 AC 22 ms
23,604 KB
testcase_04 AC 24 ms
23,784 KB
testcase_05 AC 23 ms
23,496 KB
testcase_06 AC 23 ms
23,616 KB
testcase_07 AC 24 ms
23,352 KB
testcase_08 AC 23 ms
23,616 KB
testcase_09 AC 22 ms
24,264 KB
testcase_10 AC 23 ms
23,616 KB
testcase_11 AC 23 ms
23,916 KB
testcase_12 AC 23 ms
23,604 KB
testcase_13 AC 23 ms
23,328 KB
testcase_14 AC 22 ms
24,300 KB
testcase_15 AC 23 ms
23,352 KB
testcase_16 AC 23 ms
23,352 KB
testcase_17 AC 22 ms
23,628 KB
testcase_18 AC 23 ms
24,312 KB
testcase_19 AC 23 ms
23,316 KB
testcase_20 AC 23 ms
23,304 KB
testcase_21 AC 23 ms
23,388 KB
testcase_22 AC 23 ms
23,604 KB
testcase_23 AC 22 ms
23,484 KB
testcase_24 AC 24 ms
23,628 KB
testcase_25 AC 22 ms
23,616 KB
testcase_26 AC 23 ms
23,316 KB
testcase_27 AC 23 ms
23,328 KB
testcase_28 AC 22 ms
23,796 KB
testcase_29 AC 22 ms
24,012 KB
testcase_30 AC 23 ms
24,024 KB
testcase_31 AC 23 ms
23,988 KB
testcase_32 AC 23 ms
23,976 KB
testcase_33 AC 24 ms
23,964 KB
testcase_34 AC 22 ms
23,616 KB
testcase_35 AC 24 ms
23,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int ct=0;
// int now=934751779;

int ask(int Y)
{
    ++ct;
    cout << "? " << Y << endl;
    // printf("= %d\n", now);
    // --now;
    int res;
    cin >>res;
    return res;
}

int main()
{
    int ans=-1;
    int res=ask(10);
    if(res==0)
    {
        printf("! 10\n");
        return 0;
    }

    res=ask(90);
    if(res==0) ans=90;
    else if(res==-1)
    {
        while(res!=0) res=ask(9);
        ans=9+ct-1;
    }
    else
    {
        int l=90, r=1000000000;
        while(r-l>1)
        {
            // printf("l= %d, r= %d\n", l,r);
            int m=(l+r)/2;
            res=ask(m);
            if(res==0)
            {
                ans=m+ct-1;
                break;
            }
            else if(res==-1)
            {
                --l;
                r=m;
            }
            else
            {
                --r;
                l=m-1;
            }
        }

        if(ans==-1) ans=l+ct-1;
    }

    cout << "! " << ans << endl;
    return 0;
}
0