#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long double ld;
struct point
{
int x, y;
};
int dist(int x1, int y1, int x2, int y2)
{
return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));
}
signed main()
{
int k;
cin>>k;
string s;
cin>>s;
int xl, yl, xs, ys;
cin>>xl>>yl>>xs>>ys;
vector<point> v;
v.push_back({xs, ys});
int x = xs, y = ys;
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--;
v.push_back({x, y});
}
int dx = x - xs;
int dy = y - ys;
int rmax = 0, rmin = 2e18;
for(auto it : v)
{
rmax = max(rmax, dist(it.x, it.y, xl, yl));
rmax = max(rmax, dist(it.x + (k - 1) * dx, it.y + (k - 1) * dy, xl, yl));
int st = 2, dr = k, rez = 1;
while(st <= dr)
{
int mij = (st + dr) / 2;
int d1 = dist(it.x + (mij - 1) * dx, it.y + (mij - 1) * dy, xl, yl);
int d2 = dist(it.x + (mij - 2) * dx, it.y + (mij - 2) * dy, xl, yl);
if(d1 - d2 <= 0) rez = mij, st = mij + 1;
else dr = mij - 1;
}
rmin = min(rmin, dist(it.x + (rez - 1) * dx, it.y + (rez - 1) * dy, xl, yl));
}
cout<<fixed<<setprecision(12);
cout<<(ld)sqrt(rmin)<<" "<<(ld)sqrt(rmax);
return 0;
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:30:22: 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]
30 | for(int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
2 ms |
1012 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
728 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |