#P16769. [GKS 2020 #F] Painters' Duel

    ID: 19113 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索2020剪枝记忆化搜索状压 DPGoogle Kick Start

[GKS 2020 #F] Painters' Duel

Problem Description

A new art museum is about to open! It is a single-story building in the shape of a large equilateral triangle. That triangle is made up of many smaller identical equilateral-triangle-shaped rooms, and the side length of the museum is SS times the side length of any one of the rooms. Each room has doors connecting it to all other rooms with which it shares a side (not just a vertex).

Each room is identified by 22 numbers: the row of the building it is in (counting from top to bottom, starting from 11), followed by its position within that row (counting from left to right, starting from 11). Here is an example of how the rooms are connected and labeled when S=3S = 3:

:::align{center} :::

Alma and Berthe are artists who are painting the rooms of the museum. Alma starts in the room (RA,PA)(R_A, P_A), and Berthe starts in a different room (RB,PB)(R_B, P_B). Each of them has already painted their starting room. CC of the other rooms of the museum are under construction, and neither Alma nor Berthe is allowed to enter these rooms or paint them.

Alma and Berthe are having a friendly competition and playing a turn-based game, with Alma starting first. On a painter's turn, if their current room is adjacent to at least 11 unpainted room that is not under construction, the painter must choose one of those rooms, move to it, and paint it. Otherwise, the painter cannot move and does nothing on their turn. Once both painters are unable to move, the game is over. The score of the game is the number of rooms painted by Alma minus the number of rooms painted by Berthe.

Both painters make optimal decisions, with Alma trying to maximize the score and Berthe trying to minimize the score. Given this, determine the best score Alma can guarantee for the game, regardless of what Berthe does.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each case begins with one line containing six integers SS, RAR_A, PAP_A, RBR_B, PBP_B, and CC. Respectively, these are the side length of the museum (as a multiple of the side length of a room), the row and position of Alma's starting room, the row and position of Berthe's starting room, and the number of rooms that are under construction. Then, there are CC more lines. The ii-th of these lines (counting starting from 11) contains two integers RiR_i and PiP_i, representing the row and position of the ii-th room that is under construction.

Output Format

For each test case, output one line containing Case #xx: yy`, where xx is the test case number (starting from 11) and yy is the best score that Alma can guarantee for the game, as described above.

2
2 1 1 2 1 0
2 2 2 1 1 2
2 1
2 3
Case #1: 2
Case #2: 0

2
3 3 4 2 1 2
2 3
3 1
3 3 2 2 3 2
2 1
3 1
Case #1: 0
Case #2: -1

Hint

In Sample Case #11, the turns must proceed as follows:

  • Alma moves to room (2,2)(2, 2).
  • Berthe cannot move.
  • Alma moves to room (2,3)(2, 3).
  • Berthe still cannot move.
  • Alma cannot move. Since neither painter can move, the game is now over.

Alma has painted 33 rooms and Berthe has painted 11 room, so the score is 31=23 - 1 = 2.

In Sample Case #22, neither painter can move. They only paint their starting rooms.

Limits

0CS220 \le C \le S^2 - 2.

1RAS1 \le R_A \le S.

1PA2×RA11 \le P_A \le 2 \times R_A - 1.

1RBS1 \le R_B \le S.

1PB2×RB11 \le P_B \le 2 \times R_B - 1.

(RA,PA)(RB,PB)(R_A, P_A) \ne (R_B, P_B).

1RiS1 \le R_i \le S, for all ii.

1Pi2×Ri11 \le P_i \le 2 \times R_i - 1, for all ii.

(Ri,Pi)(RA,PA)(R_i, P_i) \ne (R_A, P_A), for all ii.

(Ri,Pi)(RB,PB)(R_i, P_i) \ne (R_B, P_B), for all ii.

Either Ri<Ri+1R_i < R_{i+1}, or Ri=Ri+1R_i = R_{i+1} and Pi<Pi+1P_i < P_{i+1}, for all i<Ci < C.

Test Set 11

T=48T = 48.

S=2S = 2.

Test Set 22

1T1001 \le T \le 100.

2S62 \le S \le 6.