Codeforces Round 516 (Div. 1, by Moscow Team Olympiad)
B
Labyrinth
Codeforces
1800
原题
← AC →
翻译中…

You are playing some computer game. One of its levels puts you in a maze consisting of $*n*$ lines, each of which contains $*m*$ cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row $*r*$ and column $*c*$. In one step you can move one square up, left, down or right, if the target cell is not occupied by an obstacle. You can't move beyond the boundaries of the labyrinth.

翻译中…

Unfortunately, your keyboard is about to break, so you can move left no more than $*x*$ times and move right no more than $*y*$ times. There are no restrictions on the number of moves up and down since the keys used to move up and down are in perfect condition.

翻译中…

Now you would like to determine for each cell whether there exists a sequence of moves that will put you from the starting cell to this particular one. How many cells of the board have this property?

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*m*$ ($1 ≤ *n*, *m* ≤ 2000$) — the number of rows and the number columns in the labyrinth respectively.

翻译中…

The second line contains two integers $*r*$, $*c*$ ($1 ≤ *r* ≤ *n*$, $1 ≤ *c* ≤ *m*$) — index of the row and index of the column that define the starting cell.

翻译中…

The third line contains two integers $*x*$, $*y*$ ($0 ≤ *x*, *y* ≤ 10^{9}$) — the maximum allowed number of movements to the left and to the right respectively.

翻译中…

The next $*n*$ lines describe the labyrinth. Each of them has length of $*m*$ and consists only of symbols '.' and '*'. The $*j*$-th character of the $*i*$-th line corresponds to the cell of labyrinth at row $*i*$ and column $*j*$. Symbol '.' denotes the free cell, while symbol '*' denotes the cell with an obstacle.

翻译中…

It is guaranteed, that the starting cell contains no obstacles.

翻译中…

Output

翻译中…

Print exactly one integer — the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself.

翻译中…

Note

翻译中…

Cells, reachable in the corresponding example, are marked with '+'.

翻译中…

First example:

翻译中…

+++.. +***. +++** *+++.

翻译中…

Second example:

翻译中…

.++. .+*. .++. .++.

翻译中…

样例

Input #1
4 5
3 2
1 2
.....
.***.
...**
*....
Output #1
10
InputCopy OutputCopy
Input #2
4 4
2 2
0 1
....
..*.
....
....
Output #2
7
InputCopy OutputCopy
题目信息
题号
1063B
时间限制
2 s
内存限制
512 MB
标签
图论
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。