#P2644. 白金莲花池

白金莲花池

Description

However! When planting lotus, John discovered something interesting: some cells cannot have lotus planted directly. The reason is… to be honest, the soil in those cells contains a lot of genuine platinum, which hinders lotus growth! Coincidentally, John has just learned how to mine platinum and has the tools for it, and he also found that after mining the platinum, the cell can be planted with lotus normally, without worrying about missing soil. (Because Bessie is eager to practice, John will not mine a platinum cell unless he also intends to plant a lotus there.)

Mining platinum is tiring, just like planting lotus. Each action consumes 11 point of stamina (that is, turning a platinum cell into a lotus cell requires 22 points of stamina). John initially has PP points of stamina to plant lotus or mine platinum.

Please help John compute the least stamina needed to help Bessie complete the task, denoted by SS, and the number of ways to spend exactly that stamina to help Bessie, denoted by WSW_S. Since more platinum is better, also compute, among all solutions that spend SS stamina and help Bessie, the maximum amount of platinum that can be mined, denoted by GG, and the number of ways to help Bessie while spending SS stamina and mining exactly GG pieces of platinum, denoted by WGW_G.

If it is impossible to help Bessie within PP points of stamina, output only -1.

If it is impossible to mine any platinum within SS points of stamina, then output only -1 on the second line.

Input Format

The first line: three integers separated by spaces: PP, MM, and NN.

Lines 22 to M+1M+1: the (i+1)(i+1)-th line contains NN integers separated by spaces, describing the state of row ii of the pond:

00 means water, 11 means lotus, 22 means rock, 33 means Bessie’s starting cell, 44 means Bessie’s destination, and 55 means a platinum deposit.

Output Format

The first line: two integers separated by a space, SS and WSW_S (the minimum stamina required and the number of methods to achieve it; if it is impossible to help Bessie within PP stamina, output -1).

The second line: two integers separated by a space, GG and WGW_G (the maximum amount of platinum mined under the minimum-stamina condition and the number of methods to achieve it; if no platinum can be mined within SS stamina, output -1 on the second line).

If the first line is -1, do not output the second line.

All output numbers are guaranteed not to exceed long long.

4 5 6
0 0 0 1 0 0
2 0 0 2 0 0
0 0 5 0 0 0
3 0 0 0 4 0
0 0 2 0 0 0
2 2
1 1
3 3 2
3 5
4 2
0 1
-1

Hint

John might make a small profit by mining the platinum, but if he uses extra stamina to mine platinum without planting lotus on those cells, Bessie will be very angry!

Translated by ChatGPT 5