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 <cstdint>
#include <iostream>
#include <vector>
const long long INF = 200000LL * 200000LL;
typedef std::int_least8_t ibool;
const ibool itrue = (ibool)true;
const ibool ifalse = (ibool)false;
struct Point
{
typedef int Coord;
explicit Point(int id_, int x_ = 0, int y_ = 0)
: id(id_)
, x(x_)
, y(y_)
{
}
int id;
Coord x;
Coord y;
};
inline long long Dist(const Point & a, const Point & b)
{
return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
}
int main()
{
int n, m;
std::cin >> n >> m;
std::vector< std::vector<ibool> > used(n + 1, std::vector<ibool>(3, ifalse));
std::vector<Point> points;
std::vector<Point> anspoints(m + 1, Point(-1, -1, -1));
for (int q = 1; q <= m; ++q)
{
char type;
std::cin >> type;
if (type == 'E')
{
Point ans(q, 1, 1);
long long ansdist = -1;
for (int x = 1; x <= n; ++x)
for (int y = 1; y <= 2; ++y)
{
if (used[x][y]) continue;
Point curans(q, x, y);
long long curdist = INF;
for (auto point = points.begin(); point != points.end(); ++point)
curdist = std::min(curdist, Dist(*point, curans));
if (curdist > ansdist)
{
ans = curans;
ansdist = curdist;
}
}
used[ans.x][ans.y] = itrue;
anspoints[q] = ans;
points.push_back(ans);
}
else
{
int id;
std::cin >> id;
for (auto point = points.begin(); point != points.end(); ++point)
if (point->id == id)
{
used[point->x][point->y] = false;
std::swap(*point, *points.rbegin());
points.pop_back();
break;
}
}
}
for (int q = 1; q <= m; ++q)
if (anspoints[q].id > 0)
std::cout << anspoints[q].x << ' ' << anspoints[q].y << std::endl;
char I;
std::cin >> I;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |