def get_pos():
level = 1
pos = 1
s = input()
for i in s:
if i == '1':
level += 1
pos <<= 1
elif i == '2':
level += 1
pos <<= 1
pos += 1
elif i == 'U':
level -= 1
pos >>= 1
elif i == 'L':
pos -= 1
else:
pos += 1
return level, pos
level_a, pos_a = get_pos()
level_b, pos_b = get_pos()
if level_a < level_b:
level_a, pos_a, level_b, pos_b = level_b, pos_b, level_a, pos_a
move_up = 0
while level_a > level_b:
move_up += 1
level_a -= 1
pos_a >>= 1
if pos_a < pos_b:
pos_a, pos_b = pos_b, pos_a
ans = 100000000000000000
i = 0
while i < level_a and pos_a != pos_b:
ans = min(ans, pos_a - pos_b + (i << 1) + move_up)
i += 1
pos_a >>= 1
pos_b >>= 1
ans = min(ans, pos_a - pos_b + (i << 1) + move_up)
print(ans)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3348 KB |
Output is correct |
2 |
Correct |
21 ms |
3308 KB |
Output is correct |
3 |
Correct |
21 ms |
3356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
3460 KB |
Output is correct |
2 |
Correct |
29 ms |
3348 KB |
Output is correct |
3 |
Correct |
52 ms |
3484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
3344 KB |
Output is correct |
2 |
Correct |
21 ms |
3356 KB |
Output is correct |
3 |
Correct |
21 ms |
3328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
3452 KB |
Output is correct |
2 |
Correct |
64 ms |
3608 KB |
Output is correct |
3 |
Correct |
42 ms |
3612 KB |
Output is correct |
4 |
Correct |
22 ms |
3300 KB |
Output is correct |
5 |
Correct |
21 ms |
3308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
3300 KB |
Output is correct |
2 |
Correct |
21 ms |
3356 KB |
Output is correct |
3 |
Correct |
25 ms |
3356 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
5 |
Correct |
24 ms |
3308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
3356 KB |
Output is correct |
2 |
Correct |
28 ms |
3356 KB |
Output is correct |
3 |
Correct |
23 ms |
3308 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
3356 KB |
Output is correct |
2 |
Correct |
83 ms |
3612 KB |
Output is correct |
3 |
Correct |
55 ms |
3476 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
5 |
Correct |
31 ms |
3340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
606 ms |
3740 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
603 ms |
3640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
575 ms |
3612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |