Submission #116667

# Submission time Handle Problem Language Result Execution time Memory
116667 2019-06-13T13:30:23 Z emilem Board (CEOI13_board) C++14
30 / 100
9 ms 776 KB
#include <cassert>
#include <algorithm>
#include <iostream>
#include <string>
using std::swap;

int Depth(const std::string& a)
{
	int depth = 0;
	for (auto dir = a.begin(); dir != a.end(); ++dir)
		if (*dir == 'U')
			--depth;
		else if (*dir == '1' || *dir == '2')
			++depth;
	assert(depth >= 0);
	return depth;
}
int Coord(const std::string& a)
{
	int coord = 0;
	for (auto dir = a.begin(); dir != a.end(); ++dir)
		switch (*dir)
		{
		case '1':
			coord *= 2; break;
		case '2':
			coord *= 2;
			++coord; break;
		case 'L':
			--coord; break;
		case 'R':
			++coord; break;
		case 'U':
			coord /= 2;
		}
	return coord;
}
int main()
{
	std::string path;
	std::cin >> path;
	int aDepth = Depth(path);
	int aCoord = Coord(path);
	std::cin >> path;
	int bDepth = Depth(path);
	int bCoord = Coord(path);
	if (aDepth > bDepth)
	{
		swap(aDepth, bDepth);
		swap(aCoord, bCoord);
	}
	int depthSteps = bDepth - aDepth;
	while (bDepth > aDepth)
	{
		bCoord /= 2;
		--bDepth;
	}
	int ans = depthSteps + std::abs(aCoord - bCoord);
	while (--aDepth && --bDepth)
	{
		depthSteps += 2;
		aCoord /= 2; bCoord /= 2;
		ans = std::min(ans, depthSteps + std::abs(aCoord - bCoord));
	}
	std::cout << ans << std::endl;

	char I;
	std::cin >> I;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -