# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
116247 |
2019-06-11T14:06:03 Z |
emilem |
Tram (CEOI13_tram) |
C++14 |
|
1000 ms |
9508 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 long long Coord;
explicit Point(long long id_, long long x_ = 0, long long y_ = 0)
: id(id_)
, x(x_)
, y(y_)
{
}
long long 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()
{
long long 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 (long long 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) -> long long
{
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
{
long long 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 (long long 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 |
4 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
532 KB |
Output is correct |
2 |
Correct |
18 ms |
364 KB |
Output is correct |
3 |
Correct |
64 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
520 KB |
Output is correct |
2 |
Incorrect |
19 ms |
540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
471 ms |
8784 KB |
Output is correct |
2 |
Correct |
23 ms |
364 KB |
Output is correct |
3 |
Correct |
86 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
394 ms |
8760 KB |
Output is correct |
2 |
Incorrect |
16 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
1916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
9508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |