시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB90271435.897%

## 문제

fYanee is a bird enthusiast. Since reading about IP over Avian Carriers (IPoAC), she has spent much of her time training a flock of intelligent parrots to carry messages over long distances.

Yanee’s dream is to use her birds to send a message M to a land far far away. Her message M is a sequence of N (not necessarily distinct) integers, each between 0 and 255, inclusive. Yanee keeps K specially-trained parrots. All the parrots look the same; Yanee cannot tell them apart. Each bird can remember a single integer between 0 and R, inclusive.

Early on, she tried a simple scheme: to send a message, Yanee carefully let the birds out of the cage one by one. Before each bird soared into the air, she taught it a number from the message sequence in order. Unfortunately, this scheme did not work. Eventually, all the birds did arrive at the destination, but they did not necessarily arrive in the order in which they left. With this scheme, Yanee could recover all the numbers she sent, but she was unable to put them into the right order.

To realize her dream, Yanee will need a better scheme, and for that she needs your help. Given a message M, she plans to let the birds out one by one like before. She needs you to write a program that will perform two separate operations:

• First, your program should be able to read a message M and transform it into a sequence of at most K integers between 0 and R that she will teach the birds.
• Second, your program should be able to read the list of integers between 0 and R received as the birds reach their destination, and then transform it back to the original message M.

You may assume that all parrots always arrive at the destination, and that each of them remembers the number it was assigned. Yanee reminds you once again that the parrots may arrive in any order. Note that Yanee only has K parrots, so the sequence of integers between 0 and R that you produce must contain at most K integers.

## 구현

Write two separate procedures. One of them will be used by the sender (encoder) and the other by the receiver (decoder).

The overall process is shown in the following figure. The two procedures you are to write are:

• Procedure encode(N,M) that takes the following parameters:
• N – the length of the message.
• M – a one-dimensional array of N integers representing the message. You may assume that 0 ≤ M[i] ≤ 255 for 0 ≤ i < N.

This procedure must encode the message M into a sequence of integers between 0 and R, inclusive, that shall be sent using the parrots. To report this sequence, your procedure encode must call the procedure send(a) for each integer a that you wish to give to one of the birds.

• Procedure decode(N,L,X) that takes the following parameters:
• N – the length of the original message.
• L – the length of the message received (the number of birds that were sent).
• X – a one-dimensional array of L integers representing the received numbers. The numbers X[i] for 0 ≤ i < L are precisely the numbers that your procedure encode produced, but possibly rearranged into a different order.

This procedure must recover the original message. To report it, your procedure decode must call the procedure output(b) for each integer b in the decoded message, in the correct order.

Note that R and K are not given as input parameters – please see the subtask descriptions below. In order to correctly solve a given subtask, your procedures must satisfy the following conditions:

• All integers sent by your procedure encode must be in the range specified in the subtask.
• The number of times your procedure encode calls the procedure send must not exceed the limit K specified in the subtask. Please note that K depends on the length of the message.
• Procedure decode must correctly recover the original message M and call the procedure output(b) exactly N times, with b equal to M, M, ..., M[N-1], respectively.

In the last subtask, your score varies according to the ratio between the lengths of the encoded message and the original message.

## 예제

Consider the case where N = 3, and M= [10, 30, 20].

Procedure encode(N,M), using some strange method, may encode the message as the sequence of numbers (7, 3, 2, 70, 15, 20, 3). To report this sequence, it should call the procedure send as follows:

• send(7)
• send(3)
• send(2)
• send(70)
• send(15)
• send(20)
• send(3)

Once all parrots reach their destination, assume we obtain the following list of transcribed numbers: (3, 20, 70, 15, 2, 3, 7). The procedure decode will then be called with N=3, L=7, and X= [3, 20, 70, 15, 2, 3, 7].

The procedure decode must produce the original message (10, 30, 20). It reports the result by calling the procedure output as follows.

• output(10)
• output(30)
• output(20)

## 서브태스크 1 (17점)

• N = 8, and each integer in the array M is either 0 or 1.
• Each encoded integer must be in the range from 0 to R=65535, inclusive.
• The number of times you can call the procedure send is at most K=10×N.

## 서브태스크 2 (17점)

• 1 ≤ N ≤ 16.
• Each encoded integer must be in the range from 0 to R=65535, inclusive.
• The number of times you can call the procedure send is at most K=10×N.

## 서브태스크 3 (18점)

• 1 ≤ N ≤ 16.
• Each encoded integer must be in the range from 0 to R=255, inclusive.
• The number of times you can call the procedure send is at most K=10×N.

## 서브태스크 4 (29점)

• 1 ≤ N ≤ 32.
• Each encoded integer must be in the range from 0 to R=255, inclusive.
• The number of times you can call the procedure send is at most K=10×N.

## 서브태스크 5 (19점)

• 16 ≤ N ≤ 64.
• Each encoded integer must be in the range from 0 to R=255, inclusive.
• The number of times you can call the procedure send is at most K=15×N.
• Important: the score for this subtask depends on the ratio between the length of the encoded message and that of the original message.
For a given test case t in this subtask, let Pt=Lt/Nt be the ratio between the length Lt of the encoded message and the length Nt of the original message. Let P be the maximum of all Pt. Your score for this subtask will be determined using the following rules:
• If P ≤ 5, you get the full score of 19 points.
• If 5 < P ≤ 6, you get 18 points.
• If 6 < P ≤ 7, you get 17 points.
• If 7 < P ≤ 15, your score is 1 + 2 × (15 - P).
• If P > 15 or any of your outputs is incorrect, your score is 0.
• Important: Any valid solution for subtasks 1 to 4 will also solve all preceding subtasks. However, due to the larger bound on K, a valid solution to subtask 5 might not be able to solve subtasks 1 to 4. It is possible to solve all subtasks using the same solution.

## 제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

## 채점 및 기타 정보

• 예제는 채점하지 않는다.