#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define sp << ' ' <<
#define nl << '\n'
using namespace std;
double ans[2] = {1e9, 0};
int X[4] = {-1, 1, 0, 0};
int Y[4] = {0, 0, 1, -1};
int change(int x) {
if (x == 'L') return 0;
if (x == 'R') return 1;
if (x == 'F') return 2;
if (x == 'B') return 3;
return 0;
}
double dis(int x, int y) {return sqrt((1.0 * x * x) + (1.0 * y * y));}
void solve () {
int k; cin >> k;
string cmd; cin >> cmd;
int lx, ly, gx, gy;
cin >> lx >> ly >> gx >> gy;
gx -= lx;
gy -= ly;
int x = 0, y = 0;
for (int i = 0; cmd[i]; i++) {
if (cmd[i] == 'I') continue;
int t = change(cmd[i]);
x += X[t];
y += Y[t];
}
for (int i = 0; !i || cmd[i-1]; i++) {
if (cmd[i] == 'I') continue;
int l = 0, r = k-1;
while (l <= r) {
int M = (l + r) / 2;
double b = dis(gx + x * M, gy + y * M);
double c = dis(gx + x * (M+1), gy + y * (M+1));
if (b < c) r = M - 1;
else l = M + 1;
ans[0] = min(ans[0], b);
ans[0] = min(ans[0], c);
}
ans[1] = max(ans[1], dis(gx, gy));
ans[1] = max(ans[1], dis(gx + x * (k-1), gy + y * (k-1)));
int t = change(cmd[i]);
gx += X[t];
gy += Y[t];
}
cout << fixed;
cout << setprecision(10);
cout << ans[0] sp ans[1];
}
signed main() {IOS solve(); return 0;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |