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 14:29:34
2017-05-27 14:04:45
2017-05-27 14:01:28
2017-05-27 13:58:15
Task:Contest
Sender:Kanadan virallinen maajoukkue
Submission time:2017-05-27 14:29:34
Status:READY
Result:ACCEPTED

Show test data

Code

#include<iostream>
#include<queue>
#include<stack>

using namespace std;

// BINÄÄRIHAU ILMAN ET VOI TESTAA
// #RIP
// #REKT
// #KUOLISAATANA

//ilmeeni kun servaan jonneja: 8)
int n;

int query(int inst, int mones){
    if(mones < 1)
        return 1000000001;
    if(mones>n)
        return 0;
    int temp;
    cout << inst << " " << mones << endl;
    cin>>temp;
    return temp;
}

int main(){
    int k;
    cin>>n>>k;
    
    int ala=0, yla=n;
    
    while(ala<yla){
        int kesk = (ala + yla) / 2;
        
        int i1 = kesk;
        int a1 = i1+1;
        
        int i2 = k-kesk;
        int a2 = i2+1;
        
        
        int pi1 = query(1,i1);
        int pa1 = query(1,a1);
        int pi2 = query(2,i2);
        int pa2 = query(2,a2);
        
        if(pa2>pi1){
            yla=kesk-1;
            continue;
        }
        
        if(pa1>pi2){
            ala=kesk+1;
            continue;
        }
        
        ala = kesk;
        break;
    }
    int i1 = ala;
    int i2 = k-i1;
    int pi1 = query(1, i1);
    int pi2 = query(2, i2);
    cout<<3<<" "<<min(pi1,pi2)<<endl;
    
    return 0;
}