#P7598. [APIO2021] 六边形领域
[APIO2021] 六边形领域
Description
On a plane tiled infinitely with hexagons, Pak Dengklek stands on one cell and calls it the initial cell. If two cells in the hexagonal tiling share a common edge, they are called adjacent cells. In one move, Pak Dengklek can move from one cell to an adjacent cell in one of six possible directions (numbered from to as shown in the figure below).

Given an action sequence consisting of actions, Pak Dengklek can construct a territory from the path it produces (which corresponds to a sequence of visited cells in order). The -th action consists of a moving direction and a move length in that direction, and the path must satisfy the following properties:
- The path is closed, meaning that in the cell sequence, the starting cell and the ending cell (i.e., the initial cell) are the same.
- The path is simple, meaning that in the cell sequence, except that the initial cell is visited exactly twice (once as the start and once as the end), every other cell can be visited at most once.
- The path is exposed, meaning that in the cell sequence, every cell is adjacent to at least one non-internal cell that does not appear in the sequence.
- If a cell does not appear in the cell sequence, and starting from it, without passing through any cell in the sequence, it can reach only finitely many cells (via some number of moves), then we call this cell an internal cell.
The figure below shows an example of a path that satisfies the conditions above. In the figure:
- Cell (pink) is the initial cell.
- The numbered cells (light blue) form the cell sequence, and the numbers indicate the order in which they are visited.
- The cells marked with crosses (dark blue) are internal cells.

The constructed territory contains all cells on the path and all internal cells. The distance of a cell in the territory is defined as the minimum number of moves needed to reach from the initial cell while only passing through cells contained in the territory. The score of a cell in the territory is defined as , where and are constants given by Pak Dengklek, and is the distance of that cell in the territory. The figure below shows the distance of each cell in the territory constructed from the example path above.

Help Pak Dengklek compute the sum of scores of all cells in the territory constructed from the given action sequence. Since the total score may be very large, output the result modulo .
You need to implement the following function:
int draw_territory(int N, int A, int B, int[] D, int[] L)
- : the number of actions in the action sequence.
- : constants in the score calculation.
- : an array of length , where is the direction of the -th action.
- : an array of length , where is the move length of the -th action.
- The function should return the total score of all cells in the territory constructed from the given action sequence, modulo .
- This function will be called exactly once.
Input Format
The sample grader reads input in the following format:
- Line : .
- Line (): .
Output Format
The sample grader prints your answer in the following format:
- Line : the return value of
draw_territory.
17 2 3
1 1
2 2
3 2
4 1
5 1
4 1
3 1
2 2
1 3
6 2
2 3
3 1
4 6
5 3
6 3
6 2
1 1
1003
Hint
Sample Explanation
Consider the following call:
draw_territory(17, 2, 3,
[1, 2, 3, 4, 5, 4, 3, 2, 1, 6, 2, 3, 4, 5, 6, 6, 1],
[1, 2, 2, 1, 1, 1, 1, 2, 3, 2, 3, 1, 6, 3, 3, 2, 1])
This action sequence is the same as the example given in the statement above. The table below lists the score corresponding to each possible distance value in this territory.
| Distance value | Number of cells | Score per cell | Total score |
|---|---|---|---|
The total score is .
Therefore, draw_territory should return .
Constraints
- .
- .
- ().
- ().
- The sum of elements in does not exceed .
- The path corresponding to the given action sequence is guaranteed to be closed, simple, and exposed.
Subtasks
- (3 points): , .
- (6 points): .
- (11 points): The sum of elements in does not exceed .
- (12 points): , and the sum of elements in does not exceed .
- (15 points): .
- (19 points): The sum of elements in does not exceed .
- (18 points): ().
- (16 points): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号