#P1514. [NOIP 2010 提高组] 引水入城

    ID: 505 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp搜索2010NOIp 提高组广度优先搜索,BFS

[NOIP 2010 提高组] 引水入城

Description

In a faraway country, a scenic lake lies on one side and a boundless desert on the other. The country’s administrative divisions form an NN-by-MM rectangle, as shown above, where each cell represents a city, and each city has an elevation.

To let as many residents as possible drink clear lake water, water facilities will be built in some cities. There are two types of facilities: reservoir plants and transfer stations. A reservoir plant uses pumps to draw water from the lake into the reservoir of its city.

Therefore, only cities in the first row, which border the lake, can build reservoir plants. A transfer station uses pipelines and elevation drop to convey lake water from higher places to lower places. Thus, a city can build a transfer station only if there exists an adjacent city sharing a side, with a strictly higher elevation, that already has a water facility. Because the cities in the NN-th row are close to the desert and form the arid region, every city in that row is required to have a water facility. Can this requirement be satisfied? If yes, compute the minimum number of reservoir plants to build; if not, find how many cities in the arid region cannot possibly have any water facility.

Input Format

The first line contains two positive integers N,MN, M, representing the size of the rectangle. Then NN lines follow, each containing MM positive integers, which are the elevations of the cities in order.

Output Format

Two lines. If the requirement can be met, output the integer 11 on the first line, and output an integer on the second line representing the minimum number of reservoir plants. If the requirement cannot be met, output the integer 00 on the first line, and output an integer on the second line representing the number of cities in the arid region that cannot possibly have any water facility.

2 5
9 1 5 4 3
8 7 6 1 2

1
1

3 6
8 4 5 6 4 4
7 3 4 3 3 3
3 2 2 1 1 2
1
3

Hint

Sample 1 explanation:

You only need to build a reservoir plant in the city with elevation 99 to satisfy the requirement.

Sample 2 explanation:

In the three cities highlighted with thick borders in the figure above, building reservoir plants will satisfy the requirement. The transfer stations in the arid region fed by these three reservoir plants are marked in three colors. Of course, the construction plan may not be unique.

Constraints

This problem has 10 pieces of testdata, with limits as shown in the table below:

Testdata ID Whether requirement can be met NN\le MM\le
1 No 1010
2 100100
3 500500
4 Yes 11 1010
5 1010
6 100100 2020
7 5050
8 100100
9 200200
10 500500

For all 10 testdata, each city’s elevation does not exceed 10610^6.

Translated by ChatGPT 5