Language: C++

#include<bits/stdc++.h>

using namespace std;

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: In function 'int main()':
a.cc:47:43: error: no matching function for call to 'max(int, long long int)'
   47 |                         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:47:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   47 |                         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:47:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |                         mini=min(mini,(max(0,i-1-1))/k+1);
      |                                        ~~~^~~~~~~~~
a.cc:48:43: error: no matching function for call to 'max(int, long long int)'
   48 |                         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:48:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   48 |                         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:48:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |                         mini=min(mini,(max(0,h-i-1))/k+1);
      |                                        ~~~^~~~~~~~~
a.cc:49:51: error: no matching function for call to 'max(int, long long int)'
   49 |                                 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:49:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   49 |                                 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:49:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |                                 mini=min(mini,(max(0,j-1-1))/k+1);
      |                                                ~~~^~~~~~~~~
a.cc:50:51: error: no matching function for call to 'max(int, long long int)'
   50 |                                 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:50:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   50 |                                 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:50:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   50 |                                 mini=min(mini,(max(0,w-j-1))/k+1);
      |                                                ~~~^~~~~~~~~