Program time limit: 1 second
Program memory limit: 256 MB
There is an array containing each integer from $1$ to $n$ inclusive.
You would like to sort the array. However, the only operation you may perform is a slop:
Sort the array using at most 500 slops.
This is an interactive problem. Your program should do the following.
fflush(stdout).
In Python, use print(l, r, flush=True).If you attempt an invalid slop or perform 500 slops without sorting the array,
then the next integer your program reads will be -1, and
no further input will be provided to your program.
If using Python, you could use the following template.
N = int(input())
while True:
A = list(map(int, input().split()))
if A == [-1]:
# we messed up
exit()
if A == [i+1 for i in range(N)]:
# we succeeded
exit()
# Shuffle the first two values
print(1, 2, flush=True)
5
4 2 3 1 5
1 4
1 3 2 4 5
2 3
1 3 2 4 5
2 3
1 2 3 4 5
On the left is the input the program receives, and on the right is the output it produces.
The first slop randomly shuffles the first four values in the array.
The second slop shuffles the second and third values, but happens to do nothing.
The third slop shuffles the second and third values, and happens to swap them.
The array is now sorted, so the program terminates.
For each subtask (worth 30%, 30% and 40% of points, as per the Constraints section), your program will be run on four (4) secret test cases one after another, and if it is successful for all test cases, it solves that subtask. Your program will receive the points for each subtask it solves. Recall that your final score on the task is the score of your highest scoring submission.
The contest ended at 8:45 p.m. AEST on Tuesday 7th April. All submissions will be unofficial officially.
Log in to submit!