// 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>;
const int INF = int(1e9) + 10;
const int MX = 1e3;
int main() {
cin.tie(0)->sync_with_stdio(0);
str A, B; cin >> A >> B;
auto add = [&](str& S, bool pos) {
char c = (pos ? '0' : '1');
for(int i = sz(S)-1; i >= 0; i--) {
if (S[i] == c) {
S[i] = '0' + '1' - c;
break;
}
S[i] = c;
}
return S;
};
auto get = [&](const str& S) {
str T;
for(auto& c : S) {
if (isdigit(c)) T.push_back(c-1);
if (c == 'U') T.pop_back();
if (c == 'L') add(T, 0);
if (c == 'R') add(T, 1);
}
return T;
};
A = get(A), B = get(B);
int ans = INF;
// cout << A << " " << B << endl;
int xa = 0, xb = 0; bool aft = 0;
for(int i = 0; i < min(sz(A), sz(B)); i++) {
if (max(xa, xb) > MX) break;
if (A[i] != B[i]) aft = 1;
if (aft) {
xa = (2 * xa) + (A[i] - '0');
xb = (2 * xb) + (B[i] - '0');
}
int upa = sz(A) - i - 1, upb = sz(B) - i - 1;
ans = min(ans, upa + upb + abs(xa - xb));
}
cout << ans << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
688 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
780 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1004 ms |
924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1006 ms |
968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |