Rado dislikes writing problem statements, so we will keep this one short. The problem is interactive and the system has an array of integers . Unfortunately, you only know its length and not the values it contains. The goal is to sort all unordered pairs of positions such that the sums of their respective array elements are non-decreasing. Formally, we want to find a sequence such that:
1) For all , there exists a position , such that .
2) for all .
Since you don't know the values in , you'll be able to ask the jury questions to compare the sum of one pair of elements to the sum of another pair of elements. More formally, for some tuple , you can ask whether . You want to ask as few questions as possible.
Implementation details
Your program should implement a solve function that will be called exactly once and should the sorted sequence of pairs. Its prototype must be:
std::vector<std::pair<int, int>> solve(int n);
Your program can repeatedly call the function cmp, which has the following prototype:
bool cmp(int a, int b, int c, int d);
We refer to a call of this function as a query and it returns true, if , and false otherwise. The condition , should hold for all queries your program performs.
You should write a program which implements the solve function but it must not contain a main function. Also, it must not interact with the standard input and output and it should include the header file sqsort.h using the following preprocessor directive:
#include "sqsort.h"
As long as it fulfills these conditions, your program can contain any sort of helper functions, classes, variables, etc.
Constraints
Scoring
Every test is scored separately and the number of points you'll receive for it depends on the number of queries your program has performed before returning the sorted sequence:
- points, if or if the sequence returned by solve is not sorted as described above
- where is the maximum possible score for the test, otherwise
Local testing
You are provided with the files sqsort.h and Lgrader.cpp, which you can compile together with your program. On starting, the program will read an integer , followed by an array of integers . Then it will call your solve function and answer its cmp queries. Finally, it will print the total number of queries your program used to produce a sorted sequence or a message that the sequence is not sorted. You can modify these files however you want. The jury's grader is guaranteed to behave equivalently to Lgrader.cpp and will not adapt to your queries.
Example
β | Actions of sqsort | Actions and responses of the jury |
---|---|---|
1. | solve(3) | |
2. | cmp(0, 1, 0, 1) | return true |
3. | cmp(0, 2, 0, 0) | return true |
4. | cmp(0, 2, 0, 1) | return false |
5. | cmp(1, 2, 1, 1) | return false |
6. | cmp(2, 2, 1, 2) | return false |
7. | cmp(1, 1, 0, 1) | return true |
8. | cmp(1, 2, 0, 1) | return true |
9. | cmp(2, 2, 0, 1) | return false |
10. | cmp(2, 2, 0, 2) | return true |
11. | return {(1, 1), (1, 2), (0, 1), (2, 2), (0, 2), (0, 0)} |
Explanation
- . The array is equal to but the solve function is not given this.
The program used 9 queries and managed to correctly sort the sequence.