#include <bits/stdc++.h>
#define int long long
using namespace std;
struct point{
int x, y;
};
int dx[256], dy[256];
int dis(point A, point B){
return (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
}
long long low = 1LL << 60, high = -(1LL << 60);
point L, G, D;
void check(point X){
int d = dis(X, D);
low = min(low, d);
high = max(high, d);
}
int K;
int lim(int x){
return max(min(x, K - 1), 0LL);
}
int32_t main(){
cin >> K;
string s; cin >> s;
dx['L'] = -1; dy['L'] = 0;
dx['R'] = 1; dy['R'] = 0;
dx['F'] = 0; dy['F'] = 1;
dx['B'] = 0; dy['B'] = -1;
dx['I'] = 0; dy['I'] = 0;
int x, y; cin >> x >> y; L = {x, y}; cin >> x >> y; G = {x, y};
D = {L.x - G.x, L.y - G.y};
point X {0, 0};
vector<point> pts;
for(auto c : s){
pts.push_back(X);
X.x += dx[c]; X.y += dy[c];
}
int cx = X.x, cy = X.y;
check({cx * K, cy * K});
for(auto p : pts){
check(p); check({p.x + cx * (K - 1), p.y + cy * (K - 1)});
}
if(cx * cx + cy * cy != 0){
for(auto p : pts){
int a = cx * cx + cy * cy, b = -2LL * ((D.x - p.x) * cx + (D.y - p.y) * cy), c = (D.x - p.x) * (D.x - p.x) + (D.y - p.y) * (D.y - p.y);
int opt = -b / a / 2;
auto check_2 = [&p, &cx, &cy](int x){
check({p.x + lim(x) * cx, p.y + lim(x) * cy});
};
check_2(opt - 1); check_2(opt); check_2(opt + 1);
}
}
cout << fixed << setprecision(12) << sqrt(low) << ' ' << sqrt(high) << endl;
}
Compilation message
expgorl.cpp: In function 'int32_t main()':
expgorl.cpp:44:13: warning: array subscript has type 'char' [-Wchar-subscripts]
44 | X.x += dx[c]; X.y += dy[c];
| ^
expgorl.cpp:44:27: warning: array subscript has type 'char' [-Wchar-subscripts]
44 | X.x += dx[c]; X.y += dy[c];
| ^
expgorl.cpp:55:81: warning: unused variable 'c' [-Wunused-variable]
55 | int a = cx * cx + cy * cy, b = -2LL * ((D.x - p.x) * cx + (D.y - p.y) * cy), c = (D.x - p.x) * (D.x - p.x) + (D.y - p.y) * (D.y - p.y);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
692 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
564 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
700 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |