Language: C++

#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<pair<double,double>> u,d,l,r;
const int INF = 2e6;
signed main(){
	int n;cin >> n;
	int mxx = 1e6,mxy = 1e6,mnx = 0,mny = 0;
	rep(i,n){
		double x,y;cin >> x  >> y;
		char c;cin >> c;
		mnx = min(x,mnx);
		mny = min(y,mny);
		mxx = max(mxx,x);
		mxy = max(mxy,y);
		if(c == 'U'){
			u.push_back(P(x,y));
		}
		else if(c == 'D'){
			d.emplace_back(x,y);
		}
		else if(c == 'L'){
			l.emplace_back(x,y);
		}
		else if(c == 'R'){
			r.emplace_back(x,y);
		}
	}

	//trace(u,d,r,l);
	auto ok = [&](int x){
		// x秒後にぶつかるものがあるか（あるならtrue)
		map<pair<double,double>,int> mp;
		//up
		rep(i,u.size()){
			double nx = u[i].first,ny = u[i].second + (double)x*0.1;
			if(mp[P(nx,ny)])return true;
			mp[P(nx,ny)] = 1;
		}
		//trace(mp);
		//dowwn
		rep(i,d.size()){
			double nx = d[i].first,ny = d[i].second - (double)x*0.1;
			if(mp[P(nx,ny)])return true;
			mp[P(nx,ny)] = 1;
		}
		//trace(mp);
		//left
		rep(i,l.size()){
			double nx = l[i].first - (double)x*0.1,ny = l[i].second ;
			if(mp[P(nx,ny)])return true;
			mp[P(nx,ny)] = 1;
		}
		//right
		rep(i,r.size()){
			double nx = r[i].first + (double)x*0.1,ny = r[i].second ;
			if(mp[P(nx,ny)])return true;
			mp[P(nx,ny)] = 1;
		}
		if(mp.rbegin() > P(mxx,mxy))return true;

		return false;

	};

	int top = INF,bot = 0;
	while(top - bot > 1){

		int mid = (top + bot)/2;
		//trace(mid,ok(mid));
		if(ok(mid))top = mid;
		else bot = mid;
	}
	if(top == INF)cout << "SAFE" << endl;
	else cout << top  << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:26: error: no matching function for call to 'min(double&, long long int&)'
   61 |                 mnx = min(x,mnx);
      |                       ~~~^~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:61:26: note:   deduced conflicting types for parameter 'const _Tp' ('double' and 'long long int')
   61 |                 mnx = min(x,mnx);
      |                       ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:61:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
   61 |                 mnx = min(x,mnx);
      |                       ~~~^~~~~~~
a.cc:62:26: error: no matching function for call to 'min(double&, long long int&)'
   62 |                 mny = min(y,mny);
      |                       ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:62:26: note:   deduced conflicting types for parameter 'const _Tp' ('double' and 'long long int')
   62 |                 mny = min(y,mny);
      |                       ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:62:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
   62 |                 mny = min(y,mny);
      |                       ~~~^~~~~~~
a.cc:63:26: error: no matching function for call to 'max(long long int&, double&)'
   63 |                 mxx = max(mxx,x);
      |                       ~~~^~~~~~~
/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:63:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'double')
   63 |                 mxx = max(mxx,x);
      |                       ~~~^~~~~~~
/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:63:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |                 mxx = max(mxx,x);
      |                       ~~~^~~~~~~
a.cc:64:26: error: no matching function for call to 'max(long long int&, double&)'
   64 |                 mxy = max(mxy,y);
      |                       ~~~^~~~~~~
/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:64:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'double')
   64 |                 mxy = max(mxy,y);
      |                       ~~~^~~~~~~
/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:64:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   64 |                 mxy = max(mxy,y);
      |                       ~~~^~~~~~~
a.cc: In lambda function:
a.cc:109:32: error: no match for 'operator>' (operand types are 'std::map<std::pair<double, double>, long long int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const std::pair<double, double>, long long int> > >'} and 'P' {aka 'std::pair<long long int, long long int>'})
  109 |                 if(mp.rbegin() > P(mxx,mxy))return true;
      |                    ~~~~~~~~~~~ ^ ~~~~~~~~~~
      |                             |    |
      |                             |    P {aka std::pair<long long int, long long int>}
      |                             std::map<std::pair<double, double>, long long int>::reverse_iterator {aka std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const std::pair<double, double>, long long int> > >}
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1176:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator>(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1176 |     operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1176:5: note:   template argument deduction/substitution failed:
a.cc:109:43: note:   'std::map<std::pair<double, double>, long long int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const std::pair<double, double>, long long int> > >'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  109 |                 if(mp.rbegin() > P(mxx,mxy))return true;
      |                                           ^
/usr/include/c++/14/bits/regex.h:1236:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator>(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1236 |     operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1236:5: note:   template argument deduction/substitution failed:
a.cc:109:43: note:   'std::map<std::pair<double, double>, long long int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const std::pair<double, double>, long long int> > >'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
  109 |                 if(mp.rbegin() > P(mxx,mxy))return true;
      |                                           ^
/usr/include/c++/14/bits/regex.h:1329:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator>(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1329 |     operator>(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c+