시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 256 MB | 20 | 2 | 2 | 11.765% |
JOI Store sells N items, numbered from 0 through N − 1. The price of the item i (0 ≤ i ≤ N − 1) is Pi. The prices of any two items are different.
Anna comes to JOI Store for shopping. Among the items whose indices are between L and R, inclusive, Anna wants to buy the cheapest one. Since Anna does not know the price of each item, she will communicate with Bruno, a clerk of JOI Store, to decide which item to buy. Bruno knows the price of every item, but he does not know the values of L and R.
Anna and Bruno will use a telecommunication device to send characters. Every character they will send is 0 or 1. Anna can send at most 18 characters to Bruno, and Bruno can send at most 10 000 characters to Anna. Bruno wants to send as few characters as possible.
The values of N, L, and R will be given to Anna, and the value of N and the price of each item will be given to Bruno. Write program which implements Anna’s strategy and Bruno’s strategy so that Anna can decide which item to buy.
You need to submit two files.
The first file is Anna.cpp
. It should implement Anna’s strategy. It should implement the following function. The program should include Anna.h
using the preprocessing directive #include
.
void InitA(int N, int L, int R)
N
is the number of items N.L
and R
mean Anna wants to buy the cheapest item among the items whose indices are between L and R, inclusive.void ReceiveA(bool x)
x
denotes the character sent by Bruno to Anna. Here true
denotes the character 1, and false
denotes the character 0.int Answer()
In this file, your program can call the following function.
void SendA(bool y)
The second file is Bruno.cpp
. It should implement Bruno’s strategy. It should implement the following function. The program should include Bruno.h
using the preprocessing directive #include
.
void InitB(int N, std::vector P)
N
is the number of items N.P
is an array of length N. It means P[i]
is the price Pi of the item i (0 ≤ i ≤ N − 1).void ReceiveB(bool y)
y
denotes the character sent by Anna to Bruno. Here true
denotes the character 1, and false
denotes the character 0In this file, your program can call the following function.
void SendB(bool x)
x
denotes the character sent by Bruno to Anna. Here true
denotes the character 1, and false
denotes the character 0You can assume the program will be executed as follows. For each test case, two queues are prepared: QY for characters sent by Anna and QX for characters sent by Bruno. In the beginning, the functions InitA
and InitB
are called and characters sent by these functions are pushed to the corresponding queues. Then we will repeat the following processes.
ReceiveA
or ReceiveB
. If both QX and QY are non-empty, it is not determined which of ReceiveA
or ReceiveB
will be called.SendA
is called during executions of ReceiveA
, the sent character is pushed to QY.SendB
is called during executions of ReceiveB
, the sent character is pushed to QX.Answer
is called, and the program will be terminated.Anna should not send more than 18 characters to Bruno. If it exceeds, your program is judged as Wrong Answer [3]. Bruno should not send more than 10 000 characters to Anna. If it exceeds, your program is judged as Wrong Answer [4].
The sample grader reads the following data from the standard input.
N L R P0 P1 · · · PN−1
When the program terminates successfully, the sample grader writes the following information to the standard output (quotes for clarity).
Accepted: Y X
”.Wrong Answer [1]
”.N ≤ 1 000.
N ≤ 10 000.
No additional constraints.
Here ⌊x⌋ is the largest integer not exceeding x.
Here is a sample input for the sample grader and corresponding function calls.
Sample Input 1 | Sample Function Calls | ||
---|---|---|---|
Call | Call | Return | |
4 0 2 3 1 4 2 |
InitA(4, 0, 2) |
||
SendA(true) |
|||
SendA(false) |
|||
InitB(4, {3, 1, 4, 2}) |
|||
ReceiveB(true) |
|||
SendB(true) |
|||
ReceiveA(true) |
|||
ReceiveB(false) |
|||
Answer() |
1 |
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)