#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1058 ms |
8580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
8608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
1544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1078 ms |
8940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |