#P2492. [SDOI2011] 火星移民
[SDOI2011] 火星移民
Description
In the year 2xyz, humans have already immigrated to Mars. Due to industrial needs, people have started mining on Mars. The mining area is a regular hexagon with side length . For planning convenience, the entire area is divided into regular triangular cells (see Figure ).

There are three mines of types , , , and three refineries of types , , . Each triangular cell can be a mine, a refinery, a mountain, or flatland.
The management requires building a transportation system such that there is a road between each mine and its corresponding refinery (i.e., connects to , to , to ), and the three roads do not cross each other (that is, no triangular cell may be used by two or more roads transporting different ores). Two triangular cells are adjacent if and only if they share a common edge; roads may be built only between adjacent cells, and the cost to build such a road segment is .
Note that roads cannot be built on mountains. Due to a Martian financial crisis, the management wants to know the minimum total cost to build such a transportation system. Moreover, they want to know how many minimum-cost solutions there are.
Input Format
The first line contains an integer , the side length of the regular hexagonal mining area.
Then follow integers, given in lines, each containing integers, describing the current state of each cell. denotes flatland, denote the corresponding mine or refinery, and denotes mountain. (Sample corresponds to Figure .)
There may be multiple test cases; process until end of file.
Output Format
For each test case, output two integers: the minimum cost and the number of minimum-cost solutions. If no feasible solution exists, output . Since the number of solutions may be large, output the count modulo .
2
0 1 0 0 0
0 0 2 0 4 0 0
0 0 4 3 0 3 2
0 0 0 1 0
18 1
3
0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0 0
0 3 0 1 0 2 0
44 1
Hint
Explanation for Sample 2.

Constraints
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号