Language: C++

#include<bits/stdc++.h>

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (long long i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (long long i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (long long)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readlong long<type>()
const double pi=acos(-1.0);
typedef pair<long long, long long> PII;
typedef vector<long long> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<long long,long long> MPII;
typedef set<long long> SETI;
typedef multiset<long long> MSETI;
typedef long long long long long32;
typedef unsigned long long long ulong long32;
typedef long long long long long long64;
typedef unsigned long long long long  ulong long64;

long long h,w,k,stx,sty,dist[805][805],x[4]={0,0,1,-1},y[4]={1,-1,0,0},mini=1e9;
char g[805][805];

void ff(long long a, long long b) {
	if(a==1 || a==h || b==1 || b==w || dist[a][b]>=k) {
		return;
	}
	for(long long i=0;i<4;i++) {
		if(g[a+x[i]][b+y[i]]=='.' && dist[a+x[i]][b+y[i]]==-1 && dist[a][b]<k) {
			dist[a+x[i]][b+y[i]]=dist[a][b]+1;
			ff(a+x[i],b+y[i]);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    memset(dist,-1,sizeof(dist));
    cin>>h>>w>>k;
    for(long long i=1;i<=h;i++) {
    	for(long long j=1;j<=w;j++) {
    		cin>>g[i][j];
    		if(g[i][j]=='S') {
    			stx=i;
    			sty=j;
    			if(stx==1 || stx==h || sty==1 || sty==w) {
    				cout<<0<<endl;
    				return 0;
				}
			}
		}
	}
	dist[stx][sty]=0;
	ff(stx,sty);
	for(long long i=1;i<=h;i++) {
    	for(long long j=1;j<=w;j++) {
    		if(dist[i][j]!=-1) {
    			if(i==1 || i==h || j==1 || j==w) {
    				mini=0;
				}
    			mini=min(mini,(max(0,i-1-1))/k+1);
    			mini=min(mini,(max(0,h-i-1))/k+1);
				mini=min(mini,(max(0,j-1-1))/k+1);
				mini=min(mini,(max(0,w-j-1))/k+1);
			}
		}
	}
	cout<<mini+1<<endl;
}

Compiler output:
a.cc:37:19: error: 'long long long' is too long for GCC
   37 | typedef long long long long long32;
      |                   ^~~~
a.cc:37:24: error: 'long long long' is too long for GCC
   37 | typedef long long long long long32;
      |                        ^~~~
a.cc:38:28: error: 'long long long' is too long for GCC
   38 | typedef unsigned long long long ulong long32;
      |                            ^~~~
a.cc:38:39: error: expected initializer before 'long32'
   38 | typedef unsigned long long long ulong long32;
      |                                       ^~~~~~
a.cc:39:19: error: 'long long long' is too long for GCC
   39 | typedef long long long long long long64;
      |                   ^~~~
a.cc:39:24: error: 'long long long' is too long for GCC
   39 | typedef long long long long long long64;
      |                        ^~~~
a.cc:39:29: error: 'long long long' is too long for GCC
   39 | typedef long long long long long long64;
      |                             ^~~~
a.cc:40:28: error: 'long long long' is too long for GCC
   40 | typedef unsigned long long long long  ulong long64;
      |                            ^~~~
a.cc:40:33: error: 'long long long' is too long for GCC
   40 | typedef unsigned long long long long  ulong long64;
      |                                 ^~~~
a.cc:40:45: error: expected initializer before 'long64'
   40 | typedef unsigned long long long long  ulong long64;
      |                                             ^~~~~~
a.cc: In function 'int main()':
a.cc:84:43: error: no matching function for call to 'max(int, long long int)'
   84 |                         mini=min(mini,(max(0,i-1-1))/k+1);
      |                                        ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:84:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   84 |                         mini=min(mini,(max(0,i-1-1))/k+1);
      |                                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:84:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   84 |                         mini=min(mini,(max(0,i-1-1))/k+1);
      |                                        ~~~^~~~~~~~~
a.cc:85:43: error: no matching function for call to 'max(int, long long int)'
   85 |                         mini=min(mini,(max(0,h-i-1))/k+1);
      |                                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:85:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   85 |                         mini=min(mini,(max(0,h-i-1))/k+1);
      |                                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:85:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |                         mini=min(mini,(max(0,h-i-1))/k+1);
      |                                        ~~~^~~~~~~~~
a.cc:86:51: error: no matching function for call to 'max(int, long long int)'
   86 |                                 mini=min(mini,(max(0,j-1-1))/k+1);
      |                                                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:86:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   86 |                                 mini=min(mini,(max(0,j-1-1))/k+1);
      |                                                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:86:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   86 |                                 mini=min(mini,(max(0,j-1-1))/k+1);
      |                                                ~~~^~~~~~~~~
a.cc:87:51: error: no matching function for call to 'max(int, long long int)'
   87 |                                 mini=min(mini,(max(0,w-j-1))/k+1);
      |                                                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:87:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   87 |                                 mini=min(mini,(max(0,w-j-1))/k+1);
      |                                                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:87:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   87 |                                 mini=min(mini,(max(0,w-j-1))/k+1);
      |                                                ~~~^~~~~~~~~