A10934 | Igor and his way to work
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of $n$ rows and $m$ columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
Bankopolis looks like a grid of $n$ rows and $m$ columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
输入格式
The first line contains two integers $n$ and $m$ ( $1<=n,m<=1000$ ) — the number of rows and the number of columns in the grid.
Each of the next $n$ lines contains $m$ characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell;
- "\*" — a cell with road works;
- "S" — the cell where Igor's home is located;
- "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each.
Each of the next $n$ lines contains $m$ characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell;
- "\*" — a cell with road works;
- "S" — the cell where Igor's home is located;
- "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each.
输出格式
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
输入输出样例
输入 #1
5 5 ..S.. ****. T.... ****. .....
输出 #1
YES
输入 #2
5 5 S.... ****. ..... .**** ..T..
输出 #2
NO
The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that $4$ turns, thus there exists no path using no more than $2$ turns. The path using exactly $4$ turns is shown on this picture:

In the second sample it is impossible to reach Igor's office using less that $4$ turns, thus there exists no path using no more than $2$ turns. The path using exactly $4$ turns is shown on this picture:

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted