結果

問題 No.253 ロウソクの長さ
ユーザー TatsuyaObaTatsuyaOba
提出日時 2015-08-01 18:04:09
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 158,840 KB
実行使用メモリ 25,604 KB
平均クエリ数 29.50
最終ジャッジ日時 2024-07-16 05:33:25
合計ジャッジ時間 7,484 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#define DEBUG

using namespace std;

int cnt = 0;
#ifdef DEBUG
int max_num = 20;
#else
int max_num = 1000000000;
#endif
int min_num = 50;

int que(int num){
    cout << "? "  << num << endl;
    int rtn;
    cin >> rtn;
    cnt++;
    max_num--;
    min_num--;

#ifdef DEBUG
    cout << "cnt:" << cnt << endl;
    cout << "max_num:" << max_num << endl;
    cout << "min_num:" << min_num << endl;
#endif
    return rtn;
}

int main() {
    int ans;
    ans = que(50);
    if(ans != 1){
        while(true){
            ans = que(0);
            if(ans == 0){
                cout << "! " << cnt << endl;
                return 0;
            }
        }
    }
    while((max_num - min_num) > 1){
        int num = (max_num + min_num) / 2;
        ans = que(num);
        if(ans == 0){
            cout << "! " << num + cnt << endl;
            return 0;
        }
        if(ans == 1){
            min_num = num;
        }else{
            max_num = num -1;
        }
    }
    cout << "! " << min_num + cnt << endl;

    return 0;
}
0