CF250E.Mad Joe
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.
Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that each floor is surrounded by a concrete wall on the left and on the right.
Now Joe is on the n-th floor and in the first cell, counting from left to right. At each moment of time, Joe has the direction of his gaze, to the right or to the left (always one direction of the two). Initially, Joe looks to the right.
Joe moves by a particular algorithm. Every second he makes one of the following actions:
- If the cell directly under Joe is empty, then Joe falls down. That is, he moves to this cell, the gaze direction is preserved.
- Otherwise consider the next cell in the current direction of the gaze.
- If the cell is empty, then Joe moves into it, the gaze direction is preserved.
- If this cell has bricks, then Joe breaks them with his forehead (the cell becomes empty), and changes the direction of his gaze to the opposite.
- If this cell has a concrete wall, then Joe just changes the direction of his gaze to the opposite (concrete can withstand any number of forehead hits).
Joe calms down as soon as he reaches any cell of the first floor.
The figure below shows an example Joe's movements around the house.

Determine how many seconds Joe will need to calm down.
乔在网络世界中受到了伤害。现在他正在房子里暴怒地四处走动,摧毁沿途的一切。
乔的房子共有 n 层,每层由 m 个格子构成的一条线段组成。每个格子要么为空(即空格子),要么放置一块砖块,要么是一堵混凝土墙(始终为这三种状态之一)。我们约定:每一层的最左侧和最右侧均被一堵混凝土墙所包围。
此时,乔位于第 n 层,且处于从左往右数第 1 个格子中。在任意时刻,乔的视线方向为向右或向左(二者必居其一)。初始时,乔面朝右侧。
乔按照如下特定算法移动:每一秒,他执行以下操作之一:
- 若乔正下方的格子为空,则乔向下坠落——即移动至该格子中,视线方向保持不变;
- 否则,考察当前视线方向上的下一个格子:
- 若该格子为空,则乔向该格子移动,视线方向保持不变;
- 若该格子中为砖块,则乔用额头将其击碎(该格子变为空),并立即将视线方向反转;
- 若该格子中为混凝土墙,则乔仅将视线方向反转(混凝土墙可承受任意次数的额头撞击)。
当乔抵达第一层(即第 1 层)的任意一个格子时,他便冷静下来。
下图展示了一个乔在房中移动过程的示例:

请计算乔冷静下来所需的时间(单位:秒)。
输入格式
The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 104).
Next n lines contain the description of Joe's house. The i-th of these lines contains the description of the (n - i + 1)-th floor of the house — a line that consists of m characters: "." means an empty cell, "+" means bricks and "#" means a concrete wall.
It is guaranteed that the first cell of the n-th floor is empty.
第一行包含两个整数 n 和 m(2≤n≤100,1≤m≤104)。
接下来的 n 行描述 Joe 的房子。其中第 i 行描述房子的第 (n−i+1) 层——该行由 m 个字符组成:“.” 表示空单元格,“+” 表示砖块,“#” 表示混凝土墙。
保证第 n 层的第一个单元格为空。
输出格式
Print a single number — the number of seconds Joe needs to reach the first floor; or else, print word "Never" (without the quotes), if it can never happen.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出一个整数——Joe 到达一楼所需的秒数;否则,若该情况永远无法发生,则输出单词 "Never"(不带引号)。
请注意:在 C++ 中,请勿使用 %lld 说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
3 5 ..+.# #+..+ +.#+.
输出#1
14
输入#2
4 10 ...+.##+.+ +#++..+++# ++.#++++.. .+##.++#.+
输出#2
42
输入#3
2 2 .. ++
输出#3
Never
输入解题思路,AI测评打分。不知道怎么写?