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:59:15
2017-05-27 15:58:14
2017-05-27 15:57:12
2017-05-27 15:56:33
2017-05-27 15:33:08
2017-05-27 15:27:49
2017-05-27 15:09:19
2017-05-27 15:00:10
2017-05-27 13:46:46
Task:Contest
Sender:Proudly div 2
Submission time:2017-05-27 15:59:15
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	int a1 = 1, a2 = 1, l1 = n, l2 = n, v1, v2;

	int max1, max2, min1, min2;

	cout << "1 1" << endl; cin >> max1;
	cout << "1 " << n << endl; cin >> min1;

	cout << "2 1" << endl; cin >> max2;
	cout << "2 " << n << endl; cin >> min2;

	if(min1 > max2) {
		if(n > k) {
			cout << "1 " << k << endl; cin >> k;
			cout << "3 " << k << endl;
			return 0;
		} else {
			cout << "2 " << k-n << endl; cin >> k;
			cout << "3 " << k << endl;
			return 0;
		}
	} else if(min2 > max1) {
		if(n > k) {
			cout << "2 " << k << endl; cin >> k;
			cout << "3 " << k << endl;
			return 0;
		} else {
			cout << "1 " << k-n << endl; cin >> k;
			cout << "3 " << k << endl;
			return 0;
		}
	}

	while(l1-a1 + l2-a2 > 16) {
		int i1 = (a1+l1)/2, i2 = (a2+l2)/2;
		cout << "1 " << i1 << endl; cin >> v1;
                cout << "2 " << i2 << endl; cin >> v2;

		if(i1 + i2 < k) {
			if(v1 > v2) {
				l2 = i2;
			} else {
				l1 = i1;
			}
		} else {
			if(v1 > v2) {
				a1 = i1;
			} else {
				a2 = i2;
			}
		}

		//if(v1 > v2) {
		//	a1 = i1;
		//	l2 = i2;
		//} else {
		//	a2 = i2;
		//	l1 = i1;
		//}
	}

	vector<int> v;
	
	for(int i=a1; i<=l1; i++) {
		cout << "1 " << i << endl;
		cin >> v1; v.push_back(v1);
	}
	for(int i=a2; i<=l2; i++) {
		cout << "2 " << i << endl;
		cin >> v2; v.push_back(v2);
	}

	sort(v.rbegin(), v.rend());

	cout << "3 " << v[k - a1 - a2 + 1] << endl;
}