Universal Cup Judging System

Universal Cup

Time Limit: 4 s Memory Limit: 3584 MB Total points: 100
Statistics

A skating competition is ongoing. The rink is represented by an $n \times m$ grid, where . indicates passable ice, and # indicates obstacles that cannot be entered.

You start from a passable ice cell and performs a series of sliding actions. Each sliding action must follow these rules:

  1. Choose a direction (up, down, left, right).
  2. Slide continuously in the chosen direction until about to hit an obstacle or leave the rink boundaries, then stop.
  3. After stopping, you can choose another direction to continue sliding.

Your task is to determine for each passable cell if it can serve as a starting point such that, following the above sliding rules, every passable cell on the rink can be visited at least once.

Note that you can pass through the same cell multiple times.

It is guaranteed there is at least one passable ice cell.

Input Format

The first line contains an integer $T$, representing the number of test cases.

For each test case:

The first line contains two integers, $n$ and $m$, indicating the number of rows and columns of the grid.

The next $n$ lines each contain $m$ characters: # represents an obstacle, . represents a passable cell.

Output Format

For each test case, output a modified version of the input grid with $n$ lines and $m$ characters each:

Replace each passable cell (.) that can be a valid starting point with *. Leave other cells unchanged (# remains an obstacle, other . cells cannot be starting points).

Sample Input 1

3
3 3
...
...
...
5 5
#....
.....
.....
.#.##
.....
10 3
...
##.
...
...
.#.
.#.
.#.
##.
...
...

Sample Output 1

.*.
***
.*.
#.*..
..*..
..*..
.#*##
..*..
...
##.
.*.
***
.#.
.#.
.#.
##.
...
...

Sample Input 2

3
9 11
....#######
.##.#######
.##.#.#####
......#####
###.#.#####
###.#.#####
##..#.#####
###.#......
###.##.....
10 3
#.#
...
..#
...
...
...
.#.
.#.
.#.
#..
4 11
....#######
.#.########
...........
#..........

Sample Output 2

....#######
.##.#######
.##.#.#####
......#####
###.#.#####
###.#.#####
##**#.#####
###.#......
###.##.....
#*#
.*.
**#
.*.
.*.
.*.
.#.
.#.
.#.
#..
..*.#######
.#*########
..*........
#.*........

Scoring

For all test cases: $1 \leq T \leq 10^5$, $n \times m \leq 2 \times 10^6$, $\sum n \times m \leq 4 \times 10^6$.

Subtask $n \times m \leq$ $\sum n \times m \leq$ Points
$1$ $10$ $100\,000$ $12$
$2$ $30$ $12$
$3$ $100$ $8$
$4$ $200$ $8$
$5$ $500$ $500\,000$ $12$
$6$ $2\,000$ $2\,000\,000$ $8$
$7$ $5\,000$ $8$
$8$ $20\,000$ $8$
$9$ $100\,000$ $12$
$10$ $2\,000\,000$ $4\,000\,000$ $12$

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.