結果

問題 No.253 ロウソクの長さ
ユーザー 37kt_
提出日時 2015-10-17 21:55:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 166,020 KB
実行使用メモリ 25,476 KB
平均クエリ数 2.00
最終ジャッジ日時 2024-07-16 06:30:43
合計ジャッジ時間 9,630 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int ask(int x)
{
	static int cnt = 0;
	static map<int, int> cac;
	if (cac.count(x - cnt)) return cac[x - cnt];
	
	int res;
	cout << "? " << x - cnt++ << endl;
	cin >> res;
	return res;
}

int solve()
{
	if (ask(20) == 0) return 20;
	int l, r;
	if (ask(20) < 0) l = 0, r = 20;
	else l = 20, r = 1e9 + 10;
	while (l + 1 < r){
		int m = (l + r) / 2;
		if (ask(m) == 0) return m;
		if (ask(m) == -1) r = m;
		else l = m;
	}
	return l;
}

int main()
{
	cout << "! " << solve() << endl;
}
0