#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> m;
string s;
cin >> s;
int n = s.size();
int a, b, c, d;
cin >> a >> b >> c >> d;
int e = 0, f = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
e--;
}
if (s[i] == 'R') {
e++;
}
if (s[i] == 'F') {
f++;
}
if (s[i] == 'B') {
f--;
}
}
auto cal = [&](int a, int b) -> long double {
return sqrtl(a * a + b * b);
};
long double mn, mx;
mn = mx = cal(c - a, d - b);
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
c--;
}
if (s[i] == 'R') {
c++;
}
if (s[i] == 'F') {
d++;
}
if (s[i] == 'B') {
d--;
}
mx = max(mx, cal(c - a, d - b));
mn = min(mn, cal(c - a, d - b));
mx = max(mx, cal(c - a, d - b));
mx = max(mx, cal(c + (m - 1) * e - a, d + (m - 1) * f - b));
int l = 0, r = m;
while (r - l > 1) {
// cout << l << ' ' << r << endl;
int mi = (l + r) >> 1;
if (cal(c + mi * e - a, d + mi * f - b) >= cal(c + (mi + 1) * e - a, d + (mi + 1) * f - b)) {
l = mi;
// cout << cal(c + (mi + 1) * e - a, d + (mi + 1) * f - b) << endl;
} else {
r = mi;
}
}
for (int j = l - 10; j <= l + 10; j++) {
if (j >= 0 && j < m)
mn = min(mn, cal(c + j * e - a, d + j * f - b));
}
}
cout << fixed << setprecision(10) << mn << ' ' << mx << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
472 KB |
Output is correct |
13 |
Correct |
4 ms |
476 KB |
Output is correct |
14 |
Correct |
3 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
480 KB |
Output is correct |
17 |
Correct |
4 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
360 KB |
Output is correct |
20 |
Correct |
5 ms |
344 KB |
Output is correct |