#include<cstdio>
#include<cmath>
#include<cstring>
char str[20000];
int x[20000];
int y[20000];
inline double dist(int x,int y)
{
return sqrt(1LL*x*x+1LL*y*y);
}
int main()
{
int a,b,c,d;
int i,j,n,k;
int l,r,t1,t2;
double min=1.0E6,max=0.0,temp;
scanf("%d%s%d%d%d%d",&k,str+1,&a,&b,&c,&d);
n=strlen(str+1);
x[0]=c-a;
y[0]=d-b;
for(i=1;i<=n;i++)
{
x[i]=x[i-1];
y[i]=y[i-1];
switch(str[i])
{
case 'L':
x[i]--;
break;
case 'R':
x[i]++;
break;
case 'F':
y[i]++;
break;
case 'B':
y[i]--;
break;
default:
break;
}
}
for(i=0;i<=n;i++)
{
l=0;
r=k-1;
while(r-l>10)
{
t1=(2*l+r)/3;
t2=(l+2*r)/3;
if(dist(x[i]+(x[n]-x[0])*t1,y[i]+(y[n]-y[0])*t1)>dist(x[i]+(x[n]-x[0])*t2,y[i]+(y[n]-y[0])*t2))
l=t1;
else
r=t2;
}
for(j=(l-100>0?l-100:0);j<(r+100<k?r+100:k);j++)
{
temp=dist(x[i]+(x[n]-x[0])*j,y[i]+(y[n]-y[0])*j);
if(temp<min)min=temp;
}
temp=dist(x[i],y[i]);
if(temp>max)max=temp;
temp=dist(x[i]+(x[n]-x[0])*(k-1),y[i]+(y[n]-y[0])*(k-1));
if(temp>max)max=temp;
}
printf("%.20f %.20f",min,max);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1276 KB |
Output is correct |
2 |
Correct |
4 ms |
1276 KB |
Output is correct |
3 |
Correct |
4 ms |
1276 KB |
Output is correct |
4 |
Correct |
4 ms |
1276 KB |
Output is correct |
5 |
Correct |
4 ms |
1276 KB |
Output is correct |
6 |
Correct |
4 ms |
1276 KB |
Output is correct |
7 |
Correct |
4 ms |
1276 KB |
Output is correct |
8 |
Correct |
4 ms |
1276 KB |
Output is correct |
9 |
Correct |
16 ms |
1276 KB |
Output is correct |
10 |
Correct |
24 ms |
1276 KB |
Output is correct |
11 |
Correct |
8 ms |
1276 KB |
Output is correct |
12 |
Correct |
28 ms |
1276 KB |
Output is correct |
13 |
Correct |
28 ms |
1276 KB |
Output is correct |
14 |
Correct |
24 ms |
1276 KB |
Output is correct |
15 |
Correct |
24 ms |
1276 KB |
Output is correct |
16 |
Correct |
20 ms |
1276 KB |
Output is correct |
17 |
Correct |
20 ms |
1276 KB |
Output is correct |
18 |
Correct |
20 ms |
1276 KB |
Output is correct |
19 |
Correct |
20 ms |
1276 KB |
Output is correct |
20 |
Correct |
32 ms |
1276 KB |
Output is correct |