Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 13:16:55
2017-05-27 13:15:04
2017-05-27 13:11:34
2017-05-27 12:55:28
2017-05-27 12:52:32
2017-05-27 12:49:55
Task:Contest
Sender:Ace of Spades
Submission time:2017-05-27 13:16:55
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int lo = 0;
    int hi = k;
    if(hi > n) {
	hi = n;
	lo = k-n;
    }
    int queries = 0;
    while(lo <= hi) {
	int mid = (lo+hi)/2;
	int apos = mid;
	int bpos = k-mid;
	int aok = 1;
	int bok = 1;
	int ma = 1e9+100;
	if(apos != 0) {
	    ++queries;
	    cout<<1<<' '<<apos<<endl;
	    int q;
	    cin>>q;
	    ma = min(ma, q);
	}
	if(bpos != 0) {
	    ++queries;
	    cout<<2<<' '<<bpos<<endl;
	    int q;
	    cin>>q;
	    ma = min(ma, q);
	}
	/*
	cout<<apos<<' '<<bpos<<endl;
	cout<<"MA "<<ma<<endl;
	*/
	if(apos != n) {
	    ++queries;
	    cout<<1<<' '<<apos+1<<endl;
	    int q;
	    cin>>q;
	    if(q > ma) aok = 0;
	}
	if(bpos != n) {
	    ++queries;
	    cout<<2<<' '<<bpos+1<<endl;
	    int q;
	    cin>>q;
	    if(q > ma) bok = 0;
	}
	/*
	cout<<"lol"<<endl;
	cout<<aok<<' '<<bok<<endl;
	*/
	if(aok && bok) {
	    ++queries;
	    if(queries > 100) while(1);
	    cout<<3<<' '<<ma<<endl;
	    return 0;
	}
	if(!bok && !aok) {
	    cout<<"LOL FAIL"<<endl;
	    while(1);
	}
	if(!bok) {
	    hi = mid-1;
	}
	if(!aok) {
	    lo = mid+1;
	}
	//cout<<lo<<' '<<hi<<endl;
    }

}