結果

問題 No.253 ロウソクの長さ
ユーザー bal4ubal4u
提出日時 2019-05-10 17:40:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 27,824 KB
実行使用メモリ 24,372 KB
平均クエリ数 21.25
最終ジャッジ日時 2023-09-24 02:14:47
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,000 KB
testcase_01 AC 23 ms
23,784 KB
testcase_02 AC 23 ms
24,000 KB
testcase_03 AC 24 ms
23,820 KB
testcase_04 AC 24 ms
24,000 KB
testcase_05 AC 23 ms
23,628 KB
testcase_06 AC 25 ms
24,312 KB
testcase_07 AC 24 ms
23,988 KB
testcase_08 AC 25 ms
24,372 KB
testcase_09 AC 25 ms
23,376 KB
testcase_10 AC 26 ms
23,364 KB
testcase_11 AC 24 ms
23,412 KB
testcase_12 AC 24 ms
24,300 KB
testcase_13 AC 25 ms
23,388 KB
testcase_14 AC 24 ms
23,532 KB
testcase_15 AC 23 ms
23,376 KB
testcase_16 AC 23 ms
23,676 KB
testcase_17 AC 23 ms
23,388 KB
testcase_18 AC 25 ms
23,652 KB
testcase_19 AC 24 ms
24,312 KB
testcase_20 AC 25 ms
23,388 KB
testcase_21 AC 24 ms
23,364 KB
testcase_22 AC 24 ms
24,012 KB
testcase_23 AC 24 ms
23,628 KB
testcase_24 AC 24 ms
23,508 KB
testcase_25 AC 25 ms
23,808 KB
testcase_26 AC 25 ms
23,364 KB
testcase_27 AC 24 ms
23,652 KB
testcase_28 AC 25 ms
23,520 KB
testcase_29 AC 25 ms
24,252 KB
testcase_30 AC 26 ms
23,352 KB
testcase_31 AC 24 ms
23,640 KB
testcase_32 AC 24 ms
24,204 KB
testcase_33 AC 24 ms
23,796 KB
testcase_34 AC 24 ms
23,532 KB
testcase_35 AC 24 ms
23,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.253 ロウソクの長さ
// 2019.5.10 bal4u

#include <stdio.h>

int x = 1000000000;
int answer(int y) {
	int r;
	if (x < y) r = -1;
	else if (x > y) r = 1;
	else if (y == x) r = 0;
	x--;
	return r;
}

int ask(int y) {
	int a;
#if 0
	a = answer(y);
#else
	printf("?%d\n", y), fflush(stdout);
	scanf("%d", &a);
#endif
	return a;
}

int main()
{
	int a, k, l, r, m, ans;

	m = 100;
	a = ask(m), k = 1;
	if (a == 0) ans = m;
	else {
		k = 1;
		if (a > 0) l = m, r = 1000000001;
		else l = 9, r = m-1;
		while (l < r) {
	        m = (l + r) >> 1;
			a = ask(m);
			if (a == 0) { l = m; break; }
			k++;
		    if (a > 0) l = m, r--;
			else l--, r = m-1;
		}
		ans = l + k;
    }
	printf("!%d\n", ans), fflush(stdout);
	return 0;
}
0