結果

問題 No.253 ロウソクの長さ
ユーザー fura
提出日時 2020-06-11 01:35:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 190,892 KB
最終ジャッジ日時 2025-01-11 01:04:56
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int ask(int)’:
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int res; scanf("%d",&res);
      |                  ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int ask(int x){
	printf("? %d\n",x);
	fflush(stdout);
	int res; scanf("%d",&res);
	return res;
}

void answer(int x){
	printf("! %d\n",x);
	fflush(stdout);
}

int main(){
	int res=ask(100);
	if(res==0){
		answer(100);
	}
	else if(res==-1){
		int t;
		for(t=1;ask(0)!=0;t++);
		answer(t);
	}
	else{
		int t=1;
		int lo=100,hi=1e9+1;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			if(ask(mi-t)!=-1) lo=mi;
			else              hi=mi;
			t++;
		}
		answer(lo);
	}

	return 0;
}
0