A9829 | Pasha and Pipe
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city.
The city is an $n×m$ rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are denoted by character ' $.$ ', occupied squares are denoted by character ' $#$ '.
The pipe must meet the following criteria:
- the pipe is a polyline of width $1$ ,
- the pipe goes in empty squares,
- the pipe starts from the edge of the field, but not from a corner square,
- the pipe ends at the edge of the field but not in a corner square,
- the pipe has at most $2$ turns ( $90$ degrees),
- the border squares of the field must share exactly two squares with the pipe,
- if the pipe looks like a single segment, then the end points of the pipe must lie on distinct edges of the field,
- for each non-border square of the pipe there are exacly two side-adjacent squares that also belong to the pipe,
- for each border square of the pipe there is exactly one side-adjacent cell that also belongs to the pipe.
Here are some samples of allowed piping routes:
You were asked to write a program that calculates the number of distinct ways to make exactly one pipe in the city.
The two ways to make a pipe are considered distinct if they are distinct in at least one square.
The city is an $n×m$ rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are denoted by character ' $.$ ', occupied squares are denoted by character ' $#$ '.
The pipe must meet the following criteria:
- the pipe is a polyline of width $1$ ,
- the pipe goes in empty squares,
- the pipe starts from the edge of the field, but not from a corner square,
- the pipe ends at the edge of the field but not in a corner square,
- the pipe has at most $2$ turns ( $90$ degrees),
- the border squares of the field must share exactly two squares with the pipe,
- if the pipe looks like a single segment, then the end points of the pipe must lie on distinct edges of the field,
- for each non-border square of the pipe there are exacly two side-adjacent squares that also belong to the pipe,
- for each border square of the pipe there is exactly one side-adjacent cell that also belongs to the pipe.
Here are some samples of allowed piping routes:
<br></br> ....# ....# .*..#<br></br> ***** ****. .***.<br></br> ..#.. ..#*. ..#*.<br></br> #...# #..*# #..*#<br></br> ..... ...*. ...*.<br></br>Here are some samples of forbidden piping routes:<br></br> .**.# *...# .*.*#<br></br> ..... ****. .*.*.<br></br> ..#.. ..#*. .*#*.<br></br> #...# #..*# #*.*#<br></br> ..... ...*. .***.<br></br>In these samples the pipes are represented by characters ' $*$ '.You were asked to write a program that calculates the number of distinct ways to make exactly one pipe in the city.
The two ways to make a pipe are considered distinct if they are distinct in at least one square.
输入格式
The first line of the input contains two integers $n,m$ ( $2<=n,m<=2000$ ) — the height and width of Berland map.
Each of the next $n$ lines contains $m$ characters — the map of the city.
If the square of the map is marked by character ' $.$ ', then the square is empty and the pipe can through it.
If the square of the map is marked by character ' $#$ ', then the square is full and the pipe can't through it.
Each of the next $n$ lines contains $m$ characters — the map of the city.
If the square of the map is marked by character ' $.$ ', then the square is empty and the pipe can through it.
If the square of the map is marked by character ' $#$ ', then the square is full and the pipe can't through it.
输出格式
In the first line of the output print a single integer — the number of distinct ways to create a pipe.
输入输出样例
输入 #1
3 3 ... ..# ...
输出 #1
3
输入 #2
4 2 .. .. .. ..
输出 #2
2
输入 #3
4 5 #...# #...# ###.# ###.#
输出 #3
4
In the first sample there are 3 ways to make a pipe (the squares of the pipe are marked by characters ' $*$ '):
<br></br> .*. .*. ...<br></br> .*# **# **#<br></br> .*. ... .*.<br></br>
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted