|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||5||2||2||50.000%|
A long long time ago, in the Dreamtime, Australia was a flat grid of R rows and C columns and each grid cell was land. The rows were numbered 1 to R from North to South, and the columns were numbered 1 to C from West to East. The cell in row r and column c was denoted as (r, c). One day, the great rainbow serpent rose from the earth at (sr, sc), and moved across Australia, creating rivers wherever it slid. The serpent made M consecutive moves, each time moving to the cell directly North (N), South (S), East (E) or West (W), turning the cell into river. The cell (sr, sc) was also turned into river.
Now, millions of years later, you would like to purchase a rectangular block of cells to commemorate the creation of the rivers by the rainbow serpent. You will choose a different colour for each land cell inside your rectangular block. You would like to use as many different colours as possible but insist that every pair of adjacent land cells inside your block share the same colour. Two cells are adjacent if they share an edge. You will not choose a colour for any land cells outside your block, nor will you choose a colour for the river cells inside your block.
Given the moves made by the rainbow serpent, you would like to determine the maximum number of different colours you can choose for land cells in each of Q rectangular blocks of cells.
You need to implement the functions
init(R, C, sr, sc, M, S)--- The grader will call this function first and exactly once.
C: the number of rows and columns in the grid.
sc: the row and column where the serpent rose from the earth.
M: the number of moves the serpent made.
W, denoting that the serpent's ith move was to the cell immediately North, South, East or West of its current location, for all 0 ≤ i ≤ M - 1. You may assume that the serpent never left the grid.
colours(ar, ac, br, bc)--- After calling init once, the grader will call this function Q times in a row.
Please consult the provided template files for further details on implementing a solution specific to your programming language.
The sample grader reads the input in the following format:
W(this line should be left blank if M = 0);
|Module calls||Return value||Explanation|
||The module provides your program with the dimensions of the grid, the starting position of the serpent and the moves it made. There is no return value.|
||0||The only cell in this rectangle is (2, 3), which is a river cell. Hence, you cannot choose a colour for any land cells.|
||2||The river separates the land cells into two regions: the first region containing the cell (3, 2), and the second region containing the cells (3, 4) and (4, 4). Therefore the maximum number of different colours you can choose is 2.|
||1||All the cells in this rectangle are land cells. Since all the land cells are connected, the maximum number of different colours you can choose is 1.|
||3||The river separates the land cells into three regions: the first region containing the cells (1, 2) and (1, 3), the second region containing the cell (3, 2) and the third region containing the cell (5, 3).Therefore the maximum number of different colours you can choose is 3.|
The following diagrams correspond to the sample session above. The blue, patterned cells are river cells.
6 4 9 4 3 3 NWESSWEWS 2 3 2 3 3 2 4 4 5 3 6 4 1 2 5 3
0 2 1 3
Feedback for this sample testcase will be provided as "Sample Data" upon submission.
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)