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 15:41:49
2017-05-27 15:04:35
Task:Contest
Sender:kyy-kol
Submission time:2017-05-27 15:41:49
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <algorithm>
using namespace std;

int kysy(int n, int a, int q){
    if(a == 0) return 1e9+1;
    if(a > n ) return 0;
    cout << q << " " << a  << endl;
    cin >> a;
    return a;
}

void laske(int n, int k){
    int A1 = k, A2 = 0;
    while(A1 - A2 > 1){
        int A = (A1 - A2)/2 + A2;
        int B = k+1-A;
        
        int c=1e9+1, d=1e9+1;
        cout << "1 " << A << endl;
        cin >> c;
        cout << "2 " << B << endl;
        cin >> d;
        
        if( c < d ) A1 = A;
        else A2 = A;
    }
    
    int t[4];
    t[0] = kysy(n, A1, 1);
    t[1] = kysy(n, A2, 1);
    t[2] = kysy(n, k + 1 - A1, 2);
    t[3] = kysy(n, k + 1 - A2, 2);
    sort(t, t+4);
    
    cout << "3 " << t[2] << endl;

}

int main() {
    
    int n, k; cin >> n >> k;
    
    if(k <= n){
        laske(n, k);
        return 0;
    }
    k = 2*n - k;
    int A1 = n+1, A2 = n-k;
    while(A1 - A2 > 1){
        int A = (A1 - A2)/2 + A2;
        int B = 2*n - k- A;
        
        int c=1e9+1, d=1e9+1;
        cout << "1 " << A << endl;
        cin >> c;
        cout << "2 " << B << endl;
        cin >> d;
        
        if( c < d ) A1 = A;
        else A2 = A;
    }
    
    int t[4];
    t[0] = kysy(n, A1, 1);
    t[1] = kysy(n, A2, 1);
    t[2] = kysy(n, 2*n-k-A1, 2);
    t[3] = kysy(n, 2*n-k - A2, 2);
    sort(t, t+4);
    
    cout << "3 " << t[1] << endl;
    
}