답안 #116248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116248 2019-06-11T14:09:43 Z emilem 전차 (CEOI13_tram) C++14
65 / 100
1000 ms 9472 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;
				if (it == xCoords.begin())
				{
					curAns.push_back(Point(q, 1, 1));
					curAns.push_back(Point(q, 1, 2));
				}
				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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 Correct 314 ms 664 KB Output is correct
2 Correct 43 ms 416 KB Output is correct
3 Correct 130 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 492 KB Output is correct
2 Correct 21 ms 416 KB Output is correct
3 Correct 60 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 8684 KB Output is correct
2 Correct 22 ms 364 KB Output is correct
3 Correct 85 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 8684 KB Output is correct
2 Correct 32 ms 364 KB Output is correct
3 Correct 81 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 2084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 9472 KB Time limit exceeded
2 Halted 0 ms 0 KB -