| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 3 | 2 | 2 | 66.667% |
Sashka regularly takes part in online programming competitions. The prize for the current one is participation in a summer programming camp in the Maldives. Especially for this contest she has set her username to be Sorting. One of the tasks is the following:
The jury has come up with a permutation $p_1, p_2, p_3, \dots , p_N$ of the numbers from 1ドル$ to $N$. The task is to find the permutation and in order to do so you can ask the jury the following two types of questions:
You have to ask as few questions as possible from the first type (see the scoring section below), but the number of questions of the second type is unlimited.
Help Sashka by writing a program sorting, which by given $N$ restores the permutation. It must contain the function solve, which will be compiled and executed with a jury’s program.
The solve function must have the following prototype:
std::vector <int> solve(int N);
The function will be called with one parameter N, equal to the number of elements in the permutation. The function should return a vector with $N$ different elements – the permutation your program has found.
The compare and divisible functions are provided for questions to the jury.
The compare function has the following prototype:
bool compare(int x, int y);
The function will return true, if $p_x < p_y$ and false otherwise.
The divisible function has the following prototype:
bool divisible(int x, int y, int d);
The function will return true, if $|p_x − p_y| ≡ 0 \pmod d$ and false otherwise.
If you call the functions with invalid parameters, your program will be terminated and you will receive Wrong Answer.
You must submit the file sorting.cpp to the system which contains the solve function. It may contain other code and functions necessary for your work, but it must not contain the main function. Also, you must not read from the standard input or print to the standard output. Your program must also include the sorting.h header file by instruction to the preprocessor:
#include "sorting.h"
If you have guessed the permutation incorrectly, you will receive 0ドル$% of the points for that test. Otherwise, let you have asked $Q$ questions from the first type. Then the value of the variable $P$ is defined as follows:
Then the points which you will receive for the test are equal to: $(points\_for\_the\_test) \times P$.
solve ( 3 )
compare ( 1, 2 )
Returns value true
compare ( 1, 3 )
Returns value false
divisible ( 1, 3, 2 )
Returns value false
{ 2, 3, 1 }
For local testing you are provided with the files sorting.h and Lgrader.cpp. Place your file sorting.cpp and the two provided files in the same folder. Then compile the three files together. In such a way, you will make a program to check the correctness of your solution. The program will require the following sequence of data:
If you make an illegal call or you find the permutation incorrectly the output will contain an appropriate message. Otherwise, the output of that program will be the massage “Correct!” and the value of the variable $P,ドル calculated as described earlier.
C++17, C++20, C++17 (Clang), C++20 (Clang)