def get_pos():
level = 1
pos = 1
for i in input():
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 * 2 + move_up)
i += 1
pos_a >>= 1
pos_b >>= 1
ans = min(ans, pos_a - pos_b + i * 2 + move_up)
print(ans)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
3436 KB |
Output is correct |
2 |
Correct |
21 ms |
3308 KB |
Output is correct |
3 |
Correct |
22 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3492 KB |
Output is correct |
2 |
Correct |
28 ms |
3364 KB |
Output is correct |
3 |
Correct |
50 ms |
3740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3612 KB |
Output is correct |
2 |
Correct |
20 ms |
3308 KB |
Output is correct |
3 |
Correct |
21 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
3356 KB |
Output is correct |
2 |
Correct |
66 ms |
3732 KB |
Output is correct |
3 |
Correct |
43 ms |
3612 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
5 |
Correct |
21 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3308 KB |
Output is correct |
2 |
Correct |
21 ms |
3356 KB |
Output is correct |
3 |
Correct |
21 ms |
3300 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
5 |
Correct |
21 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3364 KB |
Output is correct |
2 |
Correct |
28 ms |
3360 KB |
Output is correct |
3 |
Correct |
21 ms |
3364 KB |
Output is correct |
4 |
Correct |
21 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3364 KB |
Output is correct |
2 |
Correct |
81 ms |
3740 KB |
Output is correct |
3 |
Correct |
50 ms |
3740 KB |
Output is correct |
4 |
Correct |
22 ms |
3308 KB |
Output is correct |
5 |
Correct |
29 ms |
3364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
586 ms |
3808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
587 ms |
3960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
599 ms |
3780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |