// NK
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()
#define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr)
//typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ord_set;
ll locationof(string s, ll nod, ll & lev){
for (int i=0; i<s.size(); i++){
if (s[i] == '1'){
nod = nod*2;
lev++;
}else if (s[i] == '2'){
nod = nod*2 + 1;
lev++;
}else if (s[i] == 'U'){
nod = nod / 2;
--lev;
}else if (s[i] == 'L'){
nod = nod - 1;
}else{ // R
nod = nod + 1;
}
}
return nod;
}
void solve(){
string a,b; cin>>a>>b;
ll AL = 0, BL = 0;
ll A = locationof(a, 1ll, AL), B = locationof(b, 1ll, BL);
//int MAXsteps = 50 * 2 + 2;
ll Log = 52;
if (AL < BL) swap(A, B), swap(AL, BL);
ll diff = AL - BL;
for (ll i = 0; i<diff; i++){
AL--;
A/=2LL;
}
int it = 0;
ll curr = 0, climb = 0;
ll Answer = 8e18;
while(1){
if (A == 0) break;
ll temp = diff + abs(A - B) + climb * 2LL;
Answer = min(Answer, temp);
climb++;
A = A / 2LL;
B = B / 2LL;
}
cout<<Answer<<'\n';
}
int main(){
Bolivia_is_nice;
int t = 1; //cin>>t;
while(t--)
solve();
return 0;
}
/*
~/.emacs
*/
Compilation message
board.cpp: In function 'll locationof(std::string, ll, ll&)':
board.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i=0; i<s.size(); i++){
| ~^~~~~~~~~
board.cpp: In function 'void solve()':
board.cpp:53:5: warning: unused variable 'Log' [-Wunused-variable]
53 | ll Log = 52;
| ^~~
board.cpp:61:6: warning: unused variable 'it' [-Wunused-variable]
61 | int it = 0;
| ^~
board.cpp:62:5: warning: unused variable 'curr' [-Wunused-variable]
62 | ll curr = 0, climb = 0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |