제출 #116667

#제출 시각아이디문제언어결과실행 시간메모리
116667emilem게임판 (CEOI13_board)C++14
30 / 100
9 ms776 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...