题目描述
有一个仅由数字00与11组成的n \times nn×n格迷宫。若你位于一格0上,那么你可以移动到相邻44格中的某一格11上,同样若你位于一格1上,那么你可以移动到相邻44格中的某一格00上。
你的任务是:对于给定的迷宫,询问从某一格开始能移动到多少个格子(包含自身)。
输入输出格式
输入格式:
第11行为两个正整数n,mn,m。
下面nn行,每行nn个字符,字符只可能是00或者11,字符之间没有空格。
接下来mm行,每行22个用空格分隔的正整数i,ji,j,对应了迷宫中第ii行第jj列的一个格子,询问从这一格开始能移动到多少格。
输出格式:
mm行,对于每个询问输出相应答案。
输入输出样例
输入样例#1: 复制
2 2 01 10 1 1 2 2
输出样例#1: 复制
4 4
说明
所有格子互相可达。
对于20\%20%的数据,n≤10n≤10;
对于40\%40%的数据,n≤50n≤50;
对于50\%50%的数据,m≤5m≤5;
对于60\%60%的数据,n≤100,m≤100n≤100,m≤100;
对于100\%100%的数据,n≤1000,m≤100000n≤1000,m≤100000。</