Sashka regularly takes part in online programming competitions. The prize for the current one is participation in a summer programming camp in the Maldives. Specially 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 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:
- Given two positions
x
andy
in the permutation , is it true that ? - Given a number
d
and two positionsx
andy
in the permutation , is it true that . In other words, is it true that the difference of the elements in the permutation at thex
-th andy
-th positions is divisible byd
?
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.
Task
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.
Implementation details
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 must have the following prototype:
bool compare(int x, int y);
The function will return true, if and false otherwise.
The divisible function must have the following prototype:
bool divisible(int x, int y, int d);
The function will return true, if and false otherwise.
If you call the functions with invalid parameters, your program will be terminated and you will receive Wrong Answer.
Your code must contain 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"
Constraints
- for each .
- for each .
Scoring
- In tests worth
20%
of the points: - In tests worth
30%
of the points: - In tests worth
40%
of the points: - In tests worth
60%
of the points: - In tests worth
100%
of the points: - If you have guessed the permutation incorrectly, you will receive
0%
of the points for that test. Otherwise, let you have askedQ
questions from the first type. Then the value of the variableP
is defined as follows:- If ,
P=1.00
. - If ,
P=0.70
. - If ,
P=0.50
. - If ,
P=0.15
. - If ,
P=0.10
. - If ,
P=0.05
.
- If ,
Then the points which you will receive for the test are equal to: .
Local testing
For local testing you are provided with the files sorting.h
and _grader.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:
- on the first line: one positive integer – the number of elements in the permutation
N
. - on the second line:
N
different positive integers, each with a value between1
andN
– the permutation that the jury has come up with.
If you make an illegal call or you find the permutation incorrectly the output will contain appropriate message. Otherwise, the output of that program will be the massage “Correct!” and the value of the variable P
, calculated as described earlier.