#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool ckmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool ckmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
string s;
ld ansmn, ansmx;
int go1[5] = {1, -1, 0, 0, 0};
int go2[5] = {0, 0, 1, -1, 0};
int dir[N];
ld dist(int x1, int y1, int x2, int y2){
return (ld)sqrtl((ld)abs(x1-x2)*abs(x1-x2) + (ld)abs(y1-y2)*abs(y1-y2));
}
int aftergy, aftergx;
void doit(int dx, int dy, int gx, int gy){
ckmin(ansmn, dist(dx, dy, gx, gy));
ckmax(ansmx, dist(dx, dy, gx, gy));
for(int i=0;i<n;i++){
gx += go1[dir[i]];
gy += go2[dir[i]];
ckmin(ansmn, dist(dx, dy, gx, gy));
ckmax(ansmx, dist(dx, dy, gx, gy));
}
aftergy = gy;
aftergx = gx;
}
void solve(int test_case){
cout << fixed << setprecision(12);
int i, j;
cin >> k;
cin >> s;
n = s.length();
for(i=0;i<n;i++){
if(s[i] == 'L')dir[i] = 1;
if(s[i] == 'R')dir[i] = 0;
if(s[i] == 'F')dir[i] = 2;
if(s[i] == 'B')dir[i] = 3;
if(s[i] == 'I')dir[i] = 4;
}
int dx, dy;
int gx, gy;
cin >> dx >> dy;
cin >> gx >> gy;
ansmn = mod*mod;
ansmx = 0.;
for(i=0;i<k;i++){
doit(dx, dy, gx, gy);
gx = aftergx;
gy = aftergy;
}
cout << ansmn << ' ' << ansmx << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
expgorl.cpp: In function 'void solve(long long int)':
expgorl.cpp:42:9: warning: unused variable 'j' [-Wunused-variable]
42 | int i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
492 KB |
Output is correct |
2 |
Correct |
369 ms |
492 KB |
Output is correct |
3 |
Correct |
408 ms |
492 KB |
Output is correct |
4 |
Correct |
429 ms |
428 KB |
Output is correct |
5 |
Correct |
219 ms |
384 KB |
Output is correct |
6 |
Correct |
331 ms |
364 KB |
Output is correct |
7 |
Correct |
372 ms |
492 KB |
Output is correct |
8 |
Correct |
502 ms |
504 KB |
Output is correct |
9 |
Execution timed out |
1084 ms |
364 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |