This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
string A;
string B;
cin >> A >> B;
ll sA = 1;
ll sB = 1;
for (char c : A){
if (c == '1') {
sA *= 2;
}
else if (c == '2') {
sA *= 2;
sA++;
}
else if (c == 'U') {
sA /= 2;
}
else if (c == 'L') {
sA--;
}
else if (c == 'R') {
sA++;
}
}
for (char c : B){
if (c == '1') {
sB *= 2;
}
else if (c == '2') {
sB *= 2;
sB++;
}
else if (c == 'U') {
sB /= 2;
}
else if (c == 'L') {
sB--;
}
else if (c == 'R') {
sB++;
}
}
if (sA < sB) {
swap(sA, sB);
}
ll d = 0;
for (int k = 62; k >= 0; k--) {
if (sB&(1LL<<k)) {
while (sA>=(1LL<<(k+1))) {
sA>>=1;
d++;
}
break;
}
}
if (sA < sB) {
swap(sA, sB);
}
ll res = (ll)(1e18);
while (sA != sB) {
res = min(res, sA-sB+d);
sA >>= 1;
sB >>= 1;
d+=2;
}
res = min(res, sA-sB+d);
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |