# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47544 | kuroni | Experiments with Gorlum (IZhO13_expgorl) | C++14 | 2 ms | 376 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 <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 10005;
const double INF = 1E18 + 7;
struct SPoint
{
long long x, y;
} g[N], o;
int k, n;
long long dx, dy;
char s[N];
double dist(const SPoint &a, int iter)
{
return hypot(dx * iter + a.x - o.x, dy * iter + a.y - o.y);
}
double TS(const SPoint &a)
{
double ret = INF;
int l = 0, r = k - 1;
while (r - l >= 3)
{
int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
double d1 = dist(a, m1), d2 = dist(a, m2);
ret = min(ret, min(d1, d2));
if (d1 > d2)
l = m1;
else
r = m2;
}
for (; l <= r; l++)
ret = min(ret, dist(a, l));
return ret;
}
int main()
{
freopen("expgorl.inp", "r", stdin);
freopen("expgorl.out", "w", stdout);
scanf("%d\n%s\n%lld %lld\n%lld %lld", &k, s + 1, &g[0].x, &g[0].y, &o.x, &o.y);
n = strlen(s + 1);
double mi = dist(g[0], 0), ma = dist(g[0], 0);
for (int i = 1; i <= n; i++)
switch (s[i])
{
case 'L':
g[i] = (SPoint){g[i - 1].x - 1, g[i - 1].y};
break;
case 'R':
g[i] = (SPoint){g[i - 1].x + 1, g[i - 1].y};
break;
case 'F':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y + 1};
break;
case 'B':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y - 1};
break;
case 'I':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y};
break;
}
dx = g[n].x - g[0].x; dy = g[n].y - g[0].y;
for (int i = 1; i <= n; i++)
{
ma = max(ma, max(dist(g[i], 0), dist(g[i], k - 1)));
mi = min(mi, TS(g[i]));
}
printf("%.16f %.16f\n", mi, ma);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |