結果

問題 No.253 ロウソクの長さ
ユーザー cormorancormoran
提出日時 2016-09-27 23:44:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 144,308 KB
実行使用メモリ 24,420 KB
平均クエリ数 22.11
最終ジャッジ日時 2023-09-24 00:34:34
合計ジャッジ時間 4,215 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,328 KB
testcase_01 AC 26 ms
23,796 KB
testcase_02 AC 27 ms
23,376 KB
testcase_03 AC 26 ms
23,988 KB
testcase_04 AC 26 ms
24,228 KB
testcase_05 AC 27 ms
23,520 KB
testcase_06 AC 27 ms
23,628 KB
testcase_07 AC 26 ms
24,000 KB
testcase_08 AC 27 ms
24,024 KB
testcase_09 AC 25 ms
23,640 KB
testcase_10 AC 27 ms
24,000 KB
testcase_11 AC 27 ms
23,508 KB
testcase_12 AC 26 ms
23,352 KB
testcase_13 AC 27 ms
24,276 KB
testcase_14 AC 26 ms
23,796 KB
testcase_15 AC 24 ms
23,592 KB
testcase_16 AC 25 ms
23,988 KB
testcase_17 AC 26 ms
24,312 KB
testcase_18 AC 26 ms
23,784 KB
testcase_19 AC 26 ms
23,580 KB
testcase_20 AC 27 ms
23,964 KB
testcase_21 AC 25 ms
24,264 KB
testcase_22 AC 26 ms
23,628 KB
testcase_23 AC 26 ms
23,520 KB
testcase_24 AC 26 ms
23,964 KB
testcase_25 AC 26 ms
24,336 KB
testcase_26 AC 27 ms
24,264 KB
testcase_27 AC 26 ms
23,520 KB
testcase_28 AC 26 ms
23,340 KB
testcase_29 AC 26 ms
23,400 KB
testcase_30 AC 26 ms
23,496 KB
testcase_31 AC 26 ms
23,400 KB
testcase_32 AC 26 ms
24,420 KB
testcase_33 AC 26 ms
23,964 KB
testcase_34 AC 25 ms
24,216 KB
testcase_35 AC 26 ms
23,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0