結果

問題 No.253 ロウソクの長さ
コンテスト
ユーザー 37kt_
提出日時 2015-10-17 21:59:12
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 583 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 981 ms
コンパイル使用メモリ 182,580 KB
実行使用メモリ 44,352 KB
最終ジャッジ日時 2026-03-30 20:20:28
合計ジャッジ時間 7,389 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int solve()':
main.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^

ソースコード

diff #
raw source code

#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()
{
	int l = 0, r = 100;
	while (l + 1 < r){
		int m = (l + r) / 2;
		if (ask(m) == 0) return m;
		if (ask(m) == -1) r = m;
		else l = m + 1;
	}
	l = 0, 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 + 1;
	}
}

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