#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 3e5+12,INF=1e9+7;
pair<double,double> p[N];
int k, tx, ty;
double laser1, laser2, gx, gy;
string s;
double disting(double x,double y){
ret (x - laser1)*(x-laser1)+(y-laser2)*(y-laser2);
}
void answer(double &ans){
double l=0,r=0,i;
for (i=0;i<s.size();++i){
if (s[i] == 'L')l--;
if (s[i] == 'R')l++;
if (s[i] == 'F')r++;
if (s[i] == 'B')r--;
ans = max(ans,disting(gx+l,gy+r));
}
l*=k-1;
r*=k-1;
for (i=0;i<s.size();++i){
if (s[i] == 'L')l--;
if (s[i] == 'R')l++;
if (s[i] == 'F')r++;
if (s[i] == 'B')r--;
ans = max(ans,disting(gx+l, gy+r));
}
}
double fun(int a){
double x = (a-1)*tx + gx;
double y = (a-1)*ty + gy;
double ans=INF;
ans = min(ans,disting(x, y));
for (int i=0;i<s.size();++i){
if (s[i] == 'L')x--;
if (s[i] == 'R')x++;
if (s[i] == 'F')y++;
if (s[i] == 'B')y--;
ans = min(ans, disting(x, y));
}
ret ans;
}
main(){
scan1(k)
cin>>s>>laser1>>laser2>>gx>>gy;
int i,j;
double mx = 0, mn = INF;
answer(mx);
for (i=0;i<s.size();++i){
if (s[i] == 'L')tx--;
if (s[i] == 'R')tx++;
if (s[i] == 'F')ty++;
if (s[i] == 'B')ty--;
}
int l=0,r=k-1;
while (l+1 < r){
int m = (l + r)>>1;
if(fun(m) <= fun(m+1)) r = m;
else l = m;
}
mn = min(fun(l), fun(r));
cout <<fixed<<setprecision(12);
cout <<sqrt(mn)<<" "<<sqrt(mx);
}
Compilation message
expgorl.cpp: In function 'double fun(long long int)':
expgorl.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp: At global scope:
expgorl.cpp:63:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main(){
| ^
expgorl.cpp: In function 'int main()':
expgorl.cpp:69:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp:66:11: warning: unused variable 'j' [-Wunused-variable]
66 | int i,j;
| ^
expgorl.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
expgorl.cpp:64:5: note: in expansion of macro 'scan1'
64 | scan1(k)
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |