Large output input, note with scanf,printf, otherwise it may time out
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>//#include < map> #include <set> #include <vector> #include <queue> #include <stack> #include <string&
Gt
using namespace Std;
#define LL Long Long const int MAXN = 505;
Char MAP[MAXN][MAXN];
BOOL VIS[MAXN][MAXN];
int N, m, Q, X1[MAXN*MAXN], Y1[MAXN*MAXN], top, ans, an[maxn][maxn];
int dis[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
void Dfs (int x, int y) {vis[x][y] = 1;
if (map[x][y] = = ' C ') ans + +;
X1[top] = x, Y1[top + +] = y;
for (int i = 0; i < 4; i + +) {int xx = x + dis[i][0];
int yy = y + dis[i][1]; if (xx >= 0 && xx < n && yy >= 0 && yy < m &&!vis[xx][yy] && map[xx][
YY] = ' # ') {dfs (xx, yy);
}} return;
} int main () {int T, case = 0; scanf ("%D ", &t);
while (T--) {scanf ("%d%d%d", &n, &m, &q);
memset (Vis, 0, sizeof (VIS));
Memset (AN,-1, sizeof (an));
for (int i = 0; i < n; i + +) {scanf ("%s", Map[i]);
} int x, y;
printf ("Case%d:\n", + + case);
for (int i = 0; i < q; i + +) {scanf ("%d%d", &x, &y);
if (an[x-1][y-1] = = 1) {top = 0, ans = 0, dfs (x-1, y-1);
} for (int j = 0; J < top; J + +) {An[x1[j]][y1[j]] = ans;
} printf ("%d\n", an[x-1][y-1]);
}
}
}