#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
int 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));
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-5;j<=l+r;j++){
mn = min(mn, cal(c + j * e - a, d + j * f - b));
}
}
cout << fixed << setprecision(10) << mn << ' ' << mx << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |