This is a function-based interactive problem.
There is a hidden grid. Each cell either contains one block or is empty. You cannot see the hidden grid directly.
You may use the following two types of lasers.
- For each row, a laser fired from left to right.
- For each column, a laser fired from top to bottom.
Each laser has an integer strength . A laser of strength penetrates the first blocks it meets in its direction, and stops at the next block. If there are at most blocks in its direction, the laser exits the grid.
You may perform at most experiments. In one experiment, you choose the strengths of all row lasers and all column lasers, and fire them simultaneously. After the experiment, you receive the stopping position of each laser, or the information that it exited the grid.
Using only the results of these experiments, find the total number of blocks in the entire grid.
Implementation details
You must include the following header file.
#include "plast.h"
You must implement the following function.
int count_blocks(int n);
Do not implement the main function. The grader provides the main function.
The function count\_blocks receives the grid size . It may call the function experiment at most times, and must return the total number of blocks in the grid.
The following function is provided by the grader.
std::vector<int> experiment(
const std::vector<int>& row_strength,
const std::vector<int>& col_strength
);
Both row\_strength and col\_strength must have length .
row\_strength[i]is the strength of the laser fired from left to right in row .col\_strength[j]is the strength of the laser fired from top to bottom in column .
Every strength must be an integer between and , inclusive.
The function experiment returns a vector of length .
- The first elements are the results of the row lasers. If the laser in row stops at column , the returned value is . If it exits the grid, the returned value is .
- The next elements are the results of the column lasers. If the laser in column stops at row , the returned value is . If it exits the grid, the returned value is .
Calling experiment more than times, passing vectors of invalid lengths, or passing strengths outside the allowed range results in Wrong Answer.
Input
This is a function-based interactive problem, so the contestant program must not read from standard input directly.
The grader passes the size of the hidden grid as the argument of count\_blocks(n).
Output
The contestant program must not print the answer to standard output directly.
The function count\_blocks(n) must return the total number of blocks in the grid.
Constraints
- .
- Each cell either contains one block or is empty.
- The function
experimentmay be called at most times. - In each experiment, every laser strength must be an integer between and , inclusive.
Subtasks
해설
관리자가 작성한 해설을 별도 페이지에서 볼 수 있어요.