結果
| 問題 | No.253 ロウソクの長さ | 
| コンテスト | |
| ユーザー |  cormoran | 
| 提出日時 | 2016-09-27 23:44:04 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 1,115 bytes | 
| コンパイル時間 | 1,835 ms | 
| コンパイル使用メモリ | 158,560 KB | 
| 実行使用メモリ | 25,476 KB | 
| 平均クエリ数 | 22.11 | 
| 最終ジャッジ日時 | 2024-07-17 00:27:18 | 
| 合計ジャッジ時間 | 4,421 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 36 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
class Solver {
  public:
    int correct = -1;
    int query(int v) {
        cout << "? " << v << endl;
        cout.flush();
        if(correct < 0) {
            int a; cin >> a;
            return a;
        } else {
            int res = v == correct ? 0 : correct > v ? 1 : -1;
            correct--;
            return res;
        }
    }    
    
    bool solve() {        
        int l = 9, r = 1e9 + 1;
        if(query(100) < 0) {
            r = 100;
        }
        
        for(int i = 1; i <= 100; i++) {
            int m = (l + r) / 2;
            int res = query(m - i);
            
            if(res > 0) l = m;
            if(res < 0) {
                r = m;                
            }
            if(res == 0) {                
                cout << "! " << m << endl;
                exit(0);
            }
        }
        return 0;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    a = -1;
    // cin >> a;
    Solver s;
    s.correct = a;
    s.solve();
    return 0;
}
            
            
            
        