#include /** 3 4 P P P P P O P X P O X P O P P P 答案:10 */ using namespace std; const int N = 110; char a[N][N]; struct Node { int x; int y; int step; }; queue q; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; int cnt; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) { cin >> a[i][j]; //记录初始病人 if (a[i][j] == 'X') q.push({i, j, 0}); } //n分钟 while (!q.empty()) { auto t = q.front(); q.pop(); //执行n分钟 if (t.step == n) break; //四个方向 for (int i = 0; i <= 3; i++) { int tx = t.x + dx[i]; int ty = t.y + dy[i]; if (tx >= 1 && tx <= m && ty >= 1 && ty <= m && a[tx][ty] == 'P') { a[tx][ty] = 'X'; q.push({tx, ty, t.step + 1}); } } } for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) if (a[i][j] == 'X')cnt++; printf("%d ", cnt); return 0; }