#include <bits/stdc++.h>
#define DIM 100010
#define INF 2000000000
using namespace std;
pair <int,int> v[DIM],w[DIM];
char s[DIM];
int n,k,i,add_x,add_y,x,y,xstart,ystart;
double get_dist (int x, int y, int x2, int y2){
return sqrt (1LL * (x-x2) * (x-x2) + 1LL * (y-y2) * (y-y2));
}
void check_points(int poz, double &sol, int tip){
for (int i=1;i<=n;i++){
int xx = v[i].first + add_x * (poz-1);
int yy = v[i].second + add_y * (poz-1);
double dist = get_dist (xx,yy,x,y);
if (!tip)
sol = max (sol,dist);
else sol = min (sol,dist);
}
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>k>>s+1;
n = strlen (s+1);
cin>>xstart>>ystart>>x>>y;
v[1] = make_pair (xstart,ystart);
int el = 1;
for (i=1;i<=n;i++){
if (s[i] == 'I')
continue;
int dx = 0, dy = 0;
if (s[i] == 'L')
dx = -1;
if (s[i] == 'R')
dx = 1;
if (s[i] == 'F')
dy = 1;
if (s[i] == 'B')
dy = -1;
++el;
v[el] = make_pair(v[el-1].first + dx, v[el-1].second + dy);
}
n = el;
if (v[1] == v[n]){
double maxi = 0, mini = INF;
check_points (1,maxi,0);
check_points (1,mini,1);
cout<<setprecision(9)<<fixed<<mini<<" "<<maxi;
return 0;
}
add_x = v[n].first - v[1].first;
add_y = v[n].second - v[1].second;
/// punctele de start
w[1] = make_pair(xstart,ystart);
for (i=2;i<=k;i++)
w[i] = make_pair(w[i-1].first + add_x, w[i-1].second + add_y);
/// distanta maxima - verific doar capetele segmentului
double maxi = 0;
check_points (1,maxi,0);
check_points (k,maxi,0);
/// distanta minima
double val = INF; int poz = 0;
for (i=1;i<=k;i++){
double dist = get_dist(w[i].first,w[i].second,x,y);
if (dist < val)
val = dist, poz = i;
}
double mini = INF;
check_points (poz,mini,1);
if (poz > 1)
check_points (poz-1,mini,1);
cout<<setprecision(9)<<fixed<<mini<<" "<<maxi;
return 0;
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:34:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | cin>>k>>s+1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |