2325: 【提高】01迷宫

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

有一个仅由数字 lns="http://www.w3.org/1998/Math/MathML">0 与 lns="http://www.w3.org/1998/Math/MathML">1 组成的 lns="http://www.w3.org/1998/Math/MathML">× 格迷宫。若你位于一格 lns="http://www.w3.org/1998/Math/MathML">0 上,那么你可以移动到相邻 lns="http://www.w3.org/1998/Math/MathML">4 格中的某一格 lns="http://www.w3.org/1998/Math/MathML">1 上,同样若你位于一格 lns="http://www.w3.org/1998/Math/MathML">1 上,那么你可以移动到相邻 lns="http://www.w3.org/1998/Math/MathML">4 格中的某一格 lns="http://www.w3.org/1998/Math/MathML">0 上。

你的任务是:对于给定的迷宫,询问从某一格开始能移动到多少个格子(包含自身)。

输入

第 lns="http://www.w3.org/1998/Math/MathML">1 行为两个正整数 lns="http://www.w3.org/1998/Math/MathML">, 。

下面 lns="http://www.w3.org/1998/Math/MathML"> 行,每行 lns="http://www.w3.org/1998/Math/MathML"> 个字符,字符只可能是 lns="http://www.w3.org/1998/Math/MathML">0 或者 lns="http://www.w3.org/1998/Math/MathML">1 ,字符之间没有空格。

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行 lns="http://www.w3.org/1998/Math/MathML">2 个用空格分隔的正整数 lns="http://www.w3.org/1998/Math/MathML">, ,对应了迷宫中第 lns="http://www.w3.org/1998/Math/MathML"> 行第 lns="http://www.w3.org/1998/Math/MathML"> 列的一个格子,询问从这一格开始能移动到多少格。

输出

 行,对于每个询问输出相应答案。

样例输入 复制

2 2
01
10
1 1
2 2

样例输出 复制

4
4

提示

对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,lns="http://www.w3.org/1998/Math/MathML">100,100

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">1000,100000