# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349043 | nicolaalexandra | Experiments with Gorlum (IZhO13_expgorl) | C++14 | 3 ms | 364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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>>x>>y>>xstart>>ystart;
v[1] = make_pair (xstart,ystart);
int el = 1;
double maxi = get_dist(xstart,ystart,x,y), mini = get_dist(xstart,ystart,x,y);
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);
maxi = max (maxi,get_dist(v[el].first,v[el].second,x,y));
mini = min (mini,get_dist(v[el].first,v[el].second,x,y));
}
n = el;
if (v[1] == v[n]){
cout<<setprecision(20)<<fixed<<mini<<" "<<maxi;
return 0;
}
add_x = v[n].first - v[1].first;
add_y = v[n].second - v[1].second;
for (i=1;i<=n;i++){
int xc = v[i].first, yc = v[i].second;
/// verific doar capetele segmentului
maxi = max (maxi,get_dist(xc,yc,x,y));
maxi = max (maxi,get_dist(xc + add_x*(k-1),yc + add_y*(k-1),x,y));
int st = 1, dr = k-1;
while (st <= dr){
int mid = (st+dr)>>1;
int xx = xc + add_x * (mid-1);
int yy = yc + add_y * (mid-1);
if (get_dist(xx,yy,x,y) > get_dist(xx+add_x,yy+add_y,x,y))
st = mid+1;
else dr = mid-1;
}
mini = min (mini,get_dist(xc + add_x*st, yc + add_y*st, x,y));
if (st > 1)
mini = min (mini,get_dist(xc + add_x*(st-1), yc + add_y*(st-1), x,y));
if (st < k)
mini = min (mini,get_dist(xc + add_x*(st+1), yc + add_y*(st+1), x,y));
}
cout<<setprecision(20)<<fixed<<mini<<" "<<maxi;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |