#include <bits/stdc++.h>
using namespace std;
long long int dist(long long int x1,long long int y1,long long int x2,long long int y2){
// cout << x1 << ' ' << y1 << " " << x2 << " " << y2 << "\n";
// cout << abs(x1-x2) << " " << abs(x1-x2)*abs(x1-x2) << " " << abs(y1-y2)*abs(y1-y2) << " " << abs(y1-y2) << "\n";
return abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2);
}
int main(){
long long int k;
string str;
long long int lsrx;
long long int lsry;
long long int grmx;
long long int grmy;
cin >> k >> str >> lsrx >> lsry >> grmx >> grmy;
long long int x=0;
long long int y=0;
str+='I';
long long int n=str.size();
for (long long int i=0;i<n;i++){
if (str[i]=='L'){
x--;
}
if (str[i]=='R'){
x++;
}
if (str[i]=='F'){
y++;
}
if (str[i]=='B'){
y--;
}
}
long long int najm=2e9+100;
long long int najv=0;
for (long long int i=0;i<n;i++){
long long int l=0;
long long int r=k-1;
long long int mid=k/2;
while (l<r){
long long int mid2=mid+1;
long long int sadxmid=grmx+x*mid;
long long int sadymid=grmy+y*mid;
long long int sadxmid2=grmx+x*mid2;
long long int sadymid2=grmy+y*mid2;
long long int distmid=dist(sadxmid,sadymid,lsrx,lsry);
long long int distmid2=dist(sadxmid2,sadymid2,lsrx,lsry);
if (distmid<distmid2){
r=mid;
}
else {
l=mid2;
}
mid=(l+r)/2;
}
//cout << grmx+x*k-x << " " << grmy+y*k-y << " " << lsrx << " " << lsry << "\n";
//cout << dist(grmx+x*k-x,grmy+y*k-y,lsrx,lsry) << "\n";
najm=min(najm,dist(grmx+x*mid,grmy+y*mid,lsrx,lsry));
najv=max(najv,dist(grmx,grmy,lsrx,lsry));
najv=max(najv,dist(grmx+x*k-x,grmy+y*k-y,lsrx,lsry));
if (str[i]=='L'){
grmx--;
}
if (str[i]=='R'){
grmx++;
}
if (str[i]=='F'){
grmy++;
}
if (str[i]=='B'){
grmy--;
}
}
cout << setprecision(200) << sqrt(najm) << " " << sqrt(najv) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |