QOJ.ac

QOJ

Puntuación total: 100 Solo salida

#12669. Deploying Troops and Generals

Estadísticas

Intelligence reports indicate that the enemy is assembling forces to launch an attack on our critical ordnance research institute. As our military is currently engaged on multiple fronts, we are unable to mobilize large numbers of troops for support. The command headquarters has decided to improve the chances of victory and minimize casualties and losses through effective pre-battle deployment.

The floor plan of the ordnance research institute can be viewed as an $N \times M$ matrix, where each $1 \times 1$ cell represents an area, and each area is adjacent to its four neighbors (up, down, left, right). Each area is one of the following three types:

  1. The area is used for military research (represented by the letter 'O');
  2. A mechanized squadron is stationed in the area (represented by '#');
  3. The area is empty ground (represented by '.').

Due to limited space, no more than one mechanized squadron can be stationed in any $1 \times 1$ cell (including one squadron), as doing so would significantly reduce mobility during combat.

Unfortunately, due to poor pre-battle estimates, our defensive deployment is quite scattered, which easily allows the enemy's specialty in surprise attack tactics to succeed. To ensure foolproof security, we have decided to use our limited defensive forces to surround all important research areas with the minimum number of movement steps. "Surrounding" means that an enemy invading from the boundary of the matrix cannot find any path to reach a research area without encountering resistance from any mechanized squadron.

Due to restrictions on internal military command authority, the headquarters can only issue an order to one of the squadrons at any given time unit (to move 1 cell up/down/left/right). Given the urgency, the headquarters hopes to complete the deployment as quickly as possible, and this task is assigned to you.

Note: During the deployment process, troops may enter research areas, but in the final deployment result, troops cannot be in any research area. Additionally, at any moment, no two troops can be in the same cell.

Input

This is a submission-based problem. All input data surround1.in through surround10.in have been stored in the contestants' directories before the start of the exam.

For each dataset: The first line contains two integers $N$ and $M$. The next $N$ lines each contain $M$ characters ('.', 'O', or '#').

Output

For the 10 given input files surround1.in through surround10.in, you need to submit your output files surround1.out through surround10.out respectively.

The first line of each output file must contain the time $T$ taken by your solution. The next $T$ lines should output each command in order, with each line containing 4 integers $x_1, y_1, x_2, y_2$, representing the movement of the troop located at $(x_1, y_1)$ to $(x_2, y_2)$.

Examples

Input 1

5 5
..##.
#...#
#OOO#
#..O#
.###.

Output 1

1
2 1 2 2

Subtasks

If the contestant's output solution is invalid (e.g., troops overlap during the execution of the plan, troops move outside the rectangular boundary, the final plan has troops and research areas in the same region, or the troops do not surround the research areas), the score is zero. Otherwise, if the time taken by the contestant's plan is $ans$, the score is calculated as follows:

$$ \text{Score} = \begin{cases} 10 & ans \le A_i \\ \left\lfloor 1 + \left( \frac{ans - B_i}{A_i - B_i} \right)^2 \times 9 \right\rfloor & A_i < ans \le B_i \\ 1 & B_i < ans \end{cases} $$

For each dataset, there are two scoring parameters $A_i$ and $B_i$, where it is guaranteed that $A_i < B_i$.

Implementation Details

We provide a tool named surround_check to test whether your output file is acceptable. The method to use this tool is:

surround_check <input filename> <output filename>

After you call this program, surround_check will provide the test results based on the input and output files you provided, which include:

  • Illegal exit: Unknown error;
  • overlap: Troops overlap, or the final plan has troops and research areas in the same region;
  • outside: Troops moved outside the rectangular boundary;
  • move error: Moving a non-existent troop, or moving a distance other than one cell;
  • not surround: Troops did not surround all research areas;
  • time not match: The number of movement steps in the output file does not match the answer;
  • yes: Output is acceptable, and it will proceed to the next step of scoring.

o sube archivos uno por uno:

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.