Submission #648072

# Submission time Handle Problem Language Result Execution time Memory
648072 2022-10-05T09:26:41 Z Kenpar Guess the number (BOI20_guess) C++17
0 / 100
0 ms 208 KB
//CSES grind baby

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

#define endl '\n'
#define ll long long

const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 2e5+1;

int ask(int x){
	int temp;
	cout<<'?'<<x<<endl;
	cout.flush();

	cin>>temp;
	return temp;
}

int bSearch(int l, int r){
	if(r >= l){
		int mid = (l+r)>>1;

		int ans = ask(mid);

		if(ans == 0){
			return mid;
		}else if(ans > 0){
			return bSearch(l, mid-1);
		}

		return bSearch(mid+1, r);
	}else{
		cout<<1;
	}
}
void solve(){
	int n;
	cin>>n;

	int ans = bSearch(1,n);

	cout<<'='<<ans;
}	


int main()
{
	//cin.tie(NULL);
	//ios::sync_with_stdio(NULL);
	int t = 1;

	//cin >> t;

	while(t--){
		solve();
		cout<<endl;
	}
}

Compilation message

Guess.cpp: In function 'int bSearch(int, int)':
Guess.cpp:36:9: warning: control reaches end of non-void function [-Wreturn-type]
   36 |   cout<<1;
      |         ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -