Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <stack>

int main()
{
	long long h, w, k, sx, sy;
 
	std::cin >> h >> w >> k;
 
	std::vector<std::string> v(h);
 
	for (long long i = 0; i < h; i++) {
		std::cin >> v[i];
		auto pos = std::find(v[i].begin(), v[i].end(), 'S');
		if (pos != v[i].end()) {
			sx = i;
			sy = pos - v[i].begin();
		}
	}
 
	std::stack<std::pair<long long, long long> > s, p;
	s.push({ sx, sy });
	p.push({ sx, sy });
 
	int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 };
	while (!s.empty()) {
		int x = s.top().first, y = s.top().second;
		s.pop();
		for (int i = 0; i < 4; i++) {
			if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) {
				continue;
			}
			if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) {
				continue;
			}
			if (v[x + xx[i]][y + yy[i]] == '.') {
				s.push({ x + xx[i], y + yy[i] });
				p.push({ x + xx[i], y + yy[i] });
			}
		}
	}
 
	long long ans = 1000000000000;
	while(!p.empty()){
		long long x = p.top().first, y = p.top().second;
		p.pop();
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k)));
	}
 
	std::cout << ans + 1 << std::endl;
 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:37: error: no matching function for call to 'find(std::__cxx11::basic_string<char>::iterator, std::__cxx11::basic_string<char>::iterator, char)'
   16 |                 auto pos = std::find(v[i].begin(), v[i].end(), 'S');
      |                            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:16:37: note:   '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   16 |                 auto pos = std::find(v[i].begin(), v[i].end(), 'S');
      |                            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:65: error: 'ceil' is not a member of 'std'
   49 |                 ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k)));
      |                                                                 ^~~~
a.cc:50:65: error: 'ceil' is not a member of 'std'
   50 |                 ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k)));
      |                                                                 ^~~~
a.cc:51:65: error: 'ceil' is not a member of 'std'
   51 |                 ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k)));
      |                                                                 ^~~~
a.cc:52:65: error: 'ceil' is not a member of 'std'
   52 |                 ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k)));
      |                                                                 ^~~~