P28902 [洛谷] Dancing Line - Random Turns
提高-
题目描述

Background

Initial direction of the line is to be determined by yourself

You can write dp

After playing with $LCA$, Imakf found it quite boring, so he opened DL.

Imakf: Assassin's Legend is stuck at $70\%$! Suddenly, I have the idea of quitting...

Imakf remembered playing DL for a year, being stuck in the Chaos of the Garden Church, and after months of hard work, finally passing it. However, he was stuck in this Assassin's Legend, unable to help but tear up. In his tears, he suddenly noticed that his phone had turned into individual pixels! Imakf was very excited! Wouldn't this allow him to write a program to automatically clear the levels?

But soon, he fell into disappointment...

Imakf: I don't know how to write it!!

Problem Description

The line is currently on a map, starting at $(1,1)$ (top-left corner) and aiming to reach $(M,N)$. It can only move down or right and must move on integer grid points.

Imakf sometimes wants to show off his skills and sometimes wants to be lazy, so he will tell you the full layout of the map, and you need to tell him the maximum and minimum number of turns required to reach the destination.

Input Format

The first line contains two positive integers $M,N$, as described in the problem.

Lines $2$ through $M+1$ each contain $N$ characters. A # indicates an obstacle, otherwise, it is clear.

Output Format

Output two positive integers $max,min$, where $max$ represents the maximum number of turns, and $min$ represents the minimum number of turns.

If it is not possible to reach the destination, output only -1.

Sample Input and Output

Sample Input #1

5 5
oooo#
ooooo
#oo#o
o#ooo
oo#oo

Sample Output #1

7 2

Sample Input #2

5 5
oooo#
ooooo
#oo##
o#o#o
oo#oo

Sample Output #2

-1

Notes

Sample $1$ Explanation:

The red route represents the maximum number of turns.

The blue route represents the minimum number of turns.


Sample $2$ Explanation:

Clearly, it is not passable.


Data Range:

Test Point $N$ $M$
$1\sim 5$ $\leq100$ $\leq100$
$6\sim 7$ $=200$ No specific limit
$8\sim 10$ No specific limit No specific limit

For all data, it is guaranteed that $10 \le M,N \le 1000$.

Thanks to @Iowa_BattleShip for pointing out data errors.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 5 oooo# ooooo #oo#o o#ooo oo#oo
样例输出
7 2