#P4294. [WC2008] 游览计划

    ID: 3230 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2008WC/CTSC/集训队Special Judge状态压缩,状压最短路进制

[WC2008] 游览计划

Description

Little D, who has never been to Shaoxing, was lucky to attend Winter Camp 2008. He was captivated by the beautiful scenery of this historic city and strongly requested to visit all scenic spots in and around Shaoxing.

The organizers divide Shaoxing into NN rows and MM columns, i.e., an (N×M)(N \times M) grid, as in the figure (8×88 \times 8):

Each scenic spot lies within a cell, and each cell contains at most one scenic spot. A cell without a scenic spot is considered a road.

For safety and convenience, based on road and security conditions, the organizers place different numbers of volunteers in some non-scenic cells; in scenic cells they hire tour guides (guides are not volunteers). When choosing a touring plan, we must ensure that between any two scenic spots there exists a path such that every cell on this path either has volunteers or is itself a scenic spot. The plan should meet contestants’ touring needs while minimizing the total number of volunteers.

For example, in the example above, each non-scenic cell is assigned a number indicating the minimum number of volunteers needed to control that cell:

The dark-shaded region shows one feasible volunteer arrangement, requiring a total of 2020 volunteers. As can be seen, two adjacent scenic spots are directly connected (via roads inside the scenic spots), e.g., 沈园 and 八字桥.

Now, please help the organizers find the best arrangement.

Input Format

The first line contains two integers, NN and MM, describing the number of cells.

The next NN lines each contain MM nonnegative integers. If an integer is 00, then the corresponding cell is a scenic spot; otherwise, it is the minimum number of volunteers required to control that cell. Adjacent integers are separated by one or more spaces; there may also be extra spaces at the beginning or end of a line.

Output Format

Output N+1N+1 lines. The first line is a single integer, the total number of volunteers in your plan.

Then output NN lines, each containing MM characters, describing the status of each cell in your plan:

  • _ (underscore) means no volunteers are placed in that cell.
  • o (lowercase letter o) means volunteers are placed in that cell.
  • x (lowercase letter x) means that cell is a scenic spot.

Note: Please strictly follow the output format. If any line is missing, or if any line contains an incorrect number of characters (and no extra spaces are allowed on any line), that test point may receive no score.

4 4
0 1 1 0
2 5 5 1
1 5 5 1
0 1 1 0
6
xoox
___o
___o
xoox

Hint

Constraints (across all 1010 groups of testdata) on NN, MM, and the number of scenic spots KK are as follows:

Test case ID NN MM KK
1 2 \le 2
2 4 \le 4 5 \le 5 4 \le 4
3 2 \le 2 10 \le 10 3 \le 3
4 6 \le 6 7 \le 7 5 \le 5
5 8 \le 8 9 \le 9 7 \le 7
6 10 \le 10 10 \le 10
7 9 \le 9 10 \le 10
8 10 \le 10 3 \le 3
9 10 \le 10
10

All integers in the input file are between 00 and 2162^{16}, inclusive.

Translated by ChatGPT 5