#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;
typedef long long LL;
typedef pair <int, int> pii;
inline int Read()
{
int x = 0, f = 1, c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 805;
const int MAXM = 640005;
const int INF = 0x3f3f3f3f;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int n, m, k, ql, qr, ans = INF, qx[MAXM], qy[MAXM], dis[MAXN][MAXN];
char s[MAXN][MAXN];
int main()
{
#ifdef wxh010910
freopen("data.in", "r", stdin);
#endif
mset(dis, INF), n = Read(), m = Read(), k = Read();
for (int i = 1; i <= n; i ++)
scanf("%s", s[i] + 1);
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
if (s[i][j] == 'S')
qx[++ qr] = i, qy[qr] = j, dis[i][j] = 0;
while (ql ^ qr)
{
int x = qx[++ ql], y = qy[ql];
if (dis[x][y] >= k)
break;
for (int i = 0; i < 4; i ++)
{
int nx = x + dx[i], ny = y + dy[i];
if (!nx || !ny || nx == n + 1 || ny == m + 1)
continue;
if (s[nx][ny] == '.' && dis[nx][ny] == INF)
dis[nx][ny] = dis[x][y] + 1, qx[++ qr] = nx, qy[qr] = ny;
}
}
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
if (dis[i][j] <= k)
ans = min(ans, (min(i - 1, min(j - 1, min(n - i, m - j))) - 1) / k + 2);
return printf("%d\n", ans), 0;
}
./Main.cpp: In function ‘int main()’:
./Main.cpp:40:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s[i] + 1);
^