import sys
readline = lambda: sys.stdin.readline().rstrip("\r\n")
def Depth(a):
depth = 0
for dir in a:
if dir == 'U':
depth -= 1
elif dir == '1' or dir == '2':
depth += 1
return depth
def Coord(a):
coord = 0
for dir in a:
if dir == '1':
coord *= 2
elif dir == '2':
coord *= 2
coord += 1
elif dir == 'L':
coord -= 1
elif dir == 'R':
coord += 1
elif dir == 'U':
coord //= 2
return coord
path = readline()
aDepth = Depth(path)
aCoord = Coord(path)
path = readline()
bDepth = Depth(path)
bCoord = Coord(path)
if aDepth > bDepth:
aDepth,bDepth = bDepth,aDepth
aCoord,bCoord = bCoord,aCoord
depthSteps = bDepth - aDepth
while bDepth > aDepth:
bDepth -= 1
bCoord //= 2
ans = depthSteps + abs(aCoord - bCoord)
while aDepth >= 1:
aDepth -= 1
depthSteps += 2
aCoord //= 2
bCoord //= 2
ans = min(ans, depthSteps + abs(aCoord - bCoord))
print(ans)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
11120 KB |
Output is correct |
2 |
Correct |
32 ms |
11112 KB |
Output is correct |
3 |
Correct |
29 ms |
11120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
14108 KB |
Output is correct |
2 |
Correct |
54 ms |
11964 KB |
Output is correct |
3 |
Correct |
54 ms |
12060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
11112 KB |
Output is correct |
2 |
Correct |
29 ms |
11112 KB |
Output is correct |
3 |
Correct |
30 ms |
11112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
14084 KB |
Output is correct |
2 |
Correct |
56 ms |
14152 KB |
Output is correct |
3 |
Correct |
62 ms |
12008 KB |
Output is correct |
4 |
Correct |
34 ms |
11112 KB |
Output is correct |
5 |
Correct |
35 ms |
11084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
11112 KB |
Output is correct |
2 |
Correct |
32 ms |
11132 KB |
Output is correct |
3 |
Correct |
29 ms |
11248 KB |
Output is correct |
4 |
Correct |
29 ms |
11120 KB |
Output is correct |
5 |
Correct |
30 ms |
11112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
12008 KB |
Output is correct |
2 |
Correct |
50 ms |
12136 KB |
Output is correct |
3 |
Correct |
30 ms |
11112 KB |
Output is correct |
4 |
Correct |
35 ms |
11152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
14180 KB |
Output is correct |
2 |
Correct |
74 ms |
14308 KB |
Output is correct |
3 |
Correct |
75 ms |
14104 KB |
Output is correct |
4 |
Correct |
29 ms |
11112 KB |
Output is correct |
5 |
Correct |
29 ms |
11244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
388 ms |
14764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
396 ms |
14960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
392 ms |
14600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |