#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t;
main(){
int K;
cin >> K;
string s;
cin >> s;
int n = s.size(); s = '#' + s;
int dx = 0, dy = 0;
for(int i = 1; i <= n; i++) {
if(s[i] == 'L') dx--;
else if(s[i] == 'R') dx++;
else if(s[i] == 'F') dy++;
else if(s[i] != 'I')dy--;
}
int x, y, X_, Y_, ans_min = 1e18, ans_max = 0;
cin >> X_ >> Y_;
cin >> x >> y;
for(int i = 0; i <= K; i++) {
int X = (x + i * dx - X_) * (x + i * dx - X_) + (y + i * dy - Y_) * (y + i * dy - Y_);
ans_min = min(ans_min, X);
ans_max = max(ans_max, X);
}
for(int i = 1; i <= n; i++) {
if(s[i] == 'L') x--;
else if(s[i] == 'R') x++;
else if(s[i] == 'F') y++;
else if(s[i] != 'I')y--;
// (x + dx * k - X_) ^ 2 + (y + dy * k - Y_) ^ 2
// k^2 * (dx^2 + dy^2) + 2 * k * (y * dy + x * dx - dy * Y_ - dx * X_)
// k aris [0 ... K - 1] shualedshi
int a = dx * dx + dy * dy, b = 2 * (y * dy + x * dx - dy * Y_ - dx * X_),
c = x * x + X_ * X_ - 2 * x * X_ + y * y + Y_ * Y_ - 2 * y * Y_;
if(a == 0) {
ans_min = min(ans_min, c);
ans_min = min(ans_min, a * (K - 1) * (K - 1) + b * (K - 1) + c);
ans_max = max(ans_max, a * (K - 1) * (K - 1) + b * (K - 1) + c);
ans_max = max(ans_max, c);
continue;
}
double k_ = - b / (double)(2 * a);
if(k_ <= 0) ans_min = min(ans_min, c);
else if(k_ >= K - 1) ans_min = min(ans_min, a * (K - 1) * (K - 1) + b * (K - 1) + c);
else {
int p = k_;
ans_min = min(ans_min, a * p * p + b * p + c);
k_++;
p = k_;
ans_min = min(ans_min, a * p * p + b * p + c);
}
ans_max = max(ans_max, max(0ll, a * (K - 1) * (K - 1) + b * (K - 1)) + c );
}
cout <<fixed << setprecision(9) << (double)sqrtl((double)ans_min) <<" " << (double)sqrtl((double)ans_max);
}
Compilation message
expgorl.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |