# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
116246 |
2019-06-11T14:04:25 Z |
emilem |
Tram (CEOI13_tram) |
C++14 |
|
1000 ms |
9068 KB |
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#include <set>
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 bool operator<(const Point & a, const Point & b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
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::set<Point::Coord> xCoords;
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 (auto it = xCoords.begin(); it != xCoords.end(); ++it)
{
Point::Coord x = *it;
Point::Coord nextX = x;
auto nextIt = it;
if (++nextIt != xCoords.end())
nextX = *nextIt;
// x ... nextX
std::vector<Point> curAns;
curAns.push_back(Point(q, x, 1));
curAns.push_back(Point(q, x, 2));
curAns.push_back(Point(q, nextX, 1));
curAns.push_back(Point(q, nextX, 2));
if (nextX == x)
{
curAns.push_back(Point(q, n, 1));
curAns.push_back(Point(q, n, 2));
}
else
{
curAns.push_back(Point(q, x + (nextX - x) / 2, 1));
curAns.push_back(Point(q, x + (nextX - x) / 2, 2));
curAns.push_back(Point(q, nextX - (nextX - x) / 2, 1));
curAns.push_back(Point(q, nextX - (nextX - x) / 2, 2));
}
auto minDist = [x, nextX, &used](const Point& point) -> int
{
long long dist = INF;
if (used[x][1]) dist = std::min(dist, Dist(point, Point(-1, x, 1)));
if (used[x][2]) dist = std::min(dist, Dist(point, Point(-1, x, 2)));
if (used[nextX][1]) dist = std::min(dist, Dist(point, Point(-1, nextX, 1)));
if (used[nextX][2]) dist = std::min(dist, Dist(point, Point(-1, nextX, 2)));
return dist;
};
for (auto point = curAns.begin(); point != curAns.end(); )
if (used[point->x][point->y])
point = curAns.erase(point);
else
++point;
Point cur = *std::max_element(curAns.begin(), curAns.end(),
[minDist](const Point& a, const Point& b) -> bool
{
auto aValue = minDist(a);
auto bValue = minDist(b);
return aValue == bValue ? b < a : aValue < bValue;
});
if (minDist(cur) > ansDist ||
(minDist(cur) == ansDist && cur < ans))
{
ansDist = minDist(cur);
ans = cur;
}
}
//
used[ans.x][ans.y] = itrue;
ansPoints[q] = ans;
xCoords.insert(ans.x);
}
else
{
int id;
std::cin >> id;
used[ansPoints[id].x][ansPoints[id].y] = false;
xCoords.erase(ansPoints[id].x);
if (used[ansPoints[id].x][1] || used[ansPoints[id].x][2])
xCoords.insert(ansPoints[id].x);
}
}
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 |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
644 KB |
Output is correct |
2 |
Correct |
21 ms |
364 KB |
Output is correct |
3 |
Correct |
51 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
492 KB |
Output is correct |
2 |
Incorrect |
18 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
342 ms |
8684 KB |
Output is correct |
2 |
Correct |
19 ms |
512 KB |
Output is correct |
3 |
Incorrect |
78 ms |
8556 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
8692 KB |
Output is correct |
2 |
Incorrect |
15 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
1748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
9068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |