結果

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

テストケース

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

ソースコード

diff #

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

#include <stdio.h>
#include <stdlib.h>

#define gc() getchar()
#define pc(c) putchar(c)

int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

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 k) {
	int a;
#if 0
	a = answer(y);
#else
	pc('?'), out(y), fflush(stdout);
	a = in();
#endif
	if (a == 0) {
		pc('!'), out(y+k);
		exit(0);
	}
	return a;
}

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

	m = 100, k = 0;
	a = ask(m, k++);
	if (a > 0) l = m, r = 1000000001;
	else l = 9, r = m-1;
	while (l < r) {
        m = (l + r) >> 1;
		a = ask(m, k++);
	    if (a > 0) l = m, r--;
		else l--, r = m-1;
	}
	pc('!'), out(l+k), fflush(stdout);
	return 0;
}
0