| #include "testlib.h" |
| #include <vector> |
|
|
| int main(int argc, char* argv[]) { |
| registerInteraction(argc, argv); |
|
|
| |
| long long n = inf.readLong(); |
|
|
| |
| long long ref_queries = ans.readLong(); |
| long long hidden_a = ans.readLong(); |
| long long hidden_b = ans.readLong(); |
|
|
| |
| if (hidden_a < 1 || hidden_a > n || hidden_b < 1 || hidden_b > n) { |
| quitf(_fail, "Invalid hidden values in .ans file"); |
| } |
|
|
| |
| println(n); |
|
|
| const int MAX_QUERIES = 10000; |
| int query_count = 0; |
|
|
| while (true) { |
| query_count++; |
| |
| if (query_count > MAX_QUERIES) { |
| quitp(0.0, "Query limit exceeded. Max queries: %d. Ratio: 0.0000", MAX_QUERIES); |
| } |
|
|
| long long x = ouf.readLong(); |
| long long y = ouf.readLong(); |
|
|
| |
| if (x < 1 || x > n || y < 1 || y > n) { |
| quitf(_wa, "Invalid query: x and y must be in range [1, %lld]", n); |
| } |
|
|
| |
| if (x == hidden_a && y == hidden_b) { |
| println(0); |
| |
| |
| double score_ratio = (double)(ref_queries + 1) / (double)(query_count + 1); |
| double unbounded_ratio = score_ratio; |
| score_ratio = std::min(1.0, score_ratio); |
| |
| quitp(score_ratio, "Correct answer in %d queries. Ratio: %.4f, RatioUnbounded: %.4f", query_count, score_ratio, unbounded_ratio); |
| break; |
| } |
|
|
| |
| std::vector<int> valid_responses; |
| |
| if (x < hidden_a) { |
| valid_responses.push_back(1); |
| } |
| if (y < hidden_b) { |
| valid_responses.push_back(2); |
| } |
| if (x > hidden_a || y > hidden_b) { |
| valid_responses.push_back(3); |
| } |
|
|
| |
| if (valid_responses.empty()) { |
| |
| quitf(_fail, "Internal error: no valid response"); |
| } |
|
|
| |
| int response = valid_responses[rnd.next(0, (int)valid_responses.size() - 1)]; |
|
|
| println(response); |
| } |
|
|
| return 0; |
| } |