#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
double lx,ly,gx,gy,tx,ty;
int n,k;
char s[MAXN];
double dis(double x,double y){
return sqrt((x-lx)*(x-lx)+(y-ly)*(y-ly));
}
double f1(int a){
double x=gx+a*tx;
double y=gy+a*ty;
double res=dis(x,y);
for(int i=0;i<n;i++){
if(s[i]=='L')
x--;
else if(s[i]=='R')
x++;
else if(s[i]=='F')
y++;
else if(s[i]=='B')
y--;
umin(res,dis(x,y));
}return res;
}
double mn(){
int st=0,en=k-1;
while(st+1<en){
int mid=(st+en)>>1;
if(f1(mid)<f1(mid+1))
en=mid;
else
st=mid;
}
return min(f1(st),f1(en));
}
double f2(int a){
double x=gx+a*tx;
double y=gy+a*ty;
double res=dis(x,y);
for(int i=0;i<n;i++){
if(s[i]=='L')
x--;
else if(s[i]=='R')
x++;
else if(s[i]=='F')
y++;
else if(s[i]=='B')
y--;
umax(res,dis(x,y));
}return res;
}
double mx(){
int st=0,en=k-1;
while(st+1<en){
int mid=(st+en)>>1;
if(f2(mid)>f2(mid+1))
en=mid;
else
st=mid;
}
return max(f2(st),f2(en));
}
int main(){
//freopen("file.in", "r", stdin);
scanf("%d",&k);
scanf("%s",s);n=strlen(s);
cin>>lx>>ly>>gx>>gy;
for(int i=0;i<n;i++){
if(s[i]=='L')
tx--;
else if(s[i]=='R')
tx++;
else if(s[i]=='F')
ty++;
else if(s[i]=='B')
ty--;
}
printf("%.12lf %.12lf\n",mn(),mx());
return 0;
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
82 | scanf("%d",&k);
| ~~~~~^~~~~~~~~
expgorl.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
83 | scanf("%s",s);n=strlen(s);
| ~~~~~^~~~~~~~
# |
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 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
364 KB |
Output is correct |
10 |
Correct |
6 ms |
536 KB |
Output is correct |
11 |
Correct |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
7 ms |
364 KB |
Output is correct |
13 |
Correct |
6 ms |
364 KB |
Output is correct |
14 |
Correct |
5 ms |
364 KB |
Output is correct |
15 |
Correct |
5 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
364 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
9 ms |
364 KB |
Output is correct |
20 |
Correct |
7 ms |
364 KB |
Output is correct |