// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define sz(x) int(x.size())
using str = string;
using ll = long long;
template<class T> using V = vector<T>;
struct node {
ll d, x;
};
const ll INF = ll(1e18) + 10;
int main() {
cin.tie(0)->sync_with_stdio(0);
str A, B; cin >> A >> B;
V<ll> PA, PB;
auto get = [&](const str& S) {
node x{0, 0};
V<ll> P;
for(auto& c : S) {
if (isdigit(c)) {
int v = c - '0' - 1;
x.d++, x.x = (2 * x.x) + v;
}
if (c == 'U') x.d--, x.x /= 2;
if (c == 'L') x.x--;
if (c == 'R') x.x++;
// cout << x.d << " " << x.x << endl;
}
while(x.d >= 0) {
P.push_back(x.x);
x.d--, x.x /= 2;
}
reverse(begin(P), end(P));
// cout << endl;
return P;
};
PA = get(A), PB = get(B);
ll ans = INF;
for(int i = 0; i < min(sz(PA), sz(PB)); i++) {
ll upa = sz(PA) - 1 - i, upb = sz(PB) - 1 - i;
ans = min(ans, upa + upb + abs(PA[i] - PB[i]));
}
cout << ans << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |