|
| 1 | +#include <iostream> |
| 2 | +#include <vector> |
| 3 | +#include <algorithm> |
| 4 | + |
| 5 | +#define all(v) (v).begin(), (v).end() |
| 6 | +using namespace std; |
| 7 | + |
| 8 | +int ask(int i, int j, string S) |
| 9 | +{ |
| 10 | + int answer; |
| 11 | + cout << S << " " << i << " " << j << "\n"; |
| 12 | + cout.flush(); |
| 13 | + cin >> answer; |
| 14 | + |
| 15 | + return answer; |
| 16 | +} |
| 17 | + |
| 18 | +int main() |
| 19 | +{ |
| 20 | + int no_of_elements, k; |
| 21 | + cin >> no_of_elements >> k; |
| 22 | + |
| 23 | + vector <int> A(no_of_elements + 1); |
| 24 | + |
| 25 | + int and_12 = ask(1, 2, "and"); |
| 26 | + int or_12 = ask(1, 2, "or"); |
| 27 | + int sum_12 = and_12 + or_12; |
| 28 | + |
| 29 | + int and_23 = ask(2, 3, "and"); |
| 30 | + int or_23 = ask(2, 3, "or"); |
| 31 | + int sum_23 = and_23 + or_23; |
| 32 | + |
| 33 | + int and_31 = ask(3, 1, "and"); |
| 34 | + int or_31 = ask(3, 1, "or"); |
| 35 | + int sum_31 = and_31 + or_31; |
| 36 | + |
| 37 | + A[1] = (sum_12 - sum_23 + sum_31)/2; |
| 38 | + A[2] = sum_12 - A[1]; |
| 39 | + A[3] = sum_23 - A[2]; //cout << A[1] << " " << A[2] << " " << A[3] << "\n"; |
| 40 | + |
| 41 | + for(int i = 4; i <= no_of_elements; i++) |
| 42 | + { |
| 43 | + int and_1i = ask(1, i, "and"); |
| 44 | + int or_1i = ask(1, i, "or"); |
| 45 | + int sum_1i = and_1i + or_1i; |
| 46 | + |
| 47 | + A[i] = sum_1i - A[1];//cout << A[i] << "\n"; |
| 48 | + } |
| 49 | + |
| 50 | + sort(all(A)); |
| 51 | + |
| 52 | + cout << "finish " << A[k] << "\n"; |
| 53 | + return 0; |
| 54 | +} |
0 commit comments