#include <cstdio>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct big{
vector<int> s;
void i(){
s.push_back(1);
}
void one(){
s.push_back(0);
}
void two(){
s.push_back(1);
}
void l(){
s.back()--;
}
void r(){
s.back()++;
}
void u(){
int r = s.back();
s.pop_back();
if(r >= 0){
s.back() += r/2;
r %= 2;
}
else{
s.back() -= r/2 * 2;
r -= r/2 * 2;
while(r < 0) s.back()--, r += 2;
}
}
}x,y;
void norm(vector<int> &v){
for (int i=(int)v.size()-1; i; i--) {
int r = v[i];
if(r >= 0){
v[i-1] += v[i]/2;
v[i] %= 2;
}
else{
v[i-1] -= v[i]/2 * 2;
v[i] -= v[i]/2 * 2;
while(v[i] < 0) v[i-1]--, v[i] += 2;
}
}
}
int main(){
char str1[100005], str2[100005];
scanf("%s %s",str1,str2);
x.i();
y.i();
for (int i=0; str1[i]; i++) {
if(str1[i] == '1') x.one();
if(str1[i] == '2') x.two();
if(str1[i] == 'L') x.l();
if(str1[i] == 'R') x.r();
if(str1[i] == 'U') x.u();
}
for (int i=0; str2[i]; i++) {
if(str2[i] == '1') y.one();
if(str2[i] == '2') y.two();
if(str2[i] == 'L') y.l();
if(str2[i] == 'R') y.r();
if(str2[i] == 'U') y.u();
}
vector<int> r1(x.s),r2(y.s);
norm(r1);
norm(r2);
int res = (int)(r1.size() + r2.size());
int piv = 0;
int rr = res;
int dist = 0;
while (piv < r1.size() && piv < r2.size()) {
dist <<= 1;
dist += r2[piv] - r1[piv];
res -= 2;
piv++;
rr = min(rr,res + abs(dist));
if(abs(dist) > 10000000) break;
}
printf("%d",rr);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1312 KB |
Output is correct |
2 |
Correct |
0 ms |
1312 KB |
Output is correct |
3 |
Correct |
0 ms |
1312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1312 KB |
Output is correct |
2 |
Correct |
0 ms |
1312 KB |
Output is correct |
3 |
Correct |
0 ms |
1308 KB |
Output is correct |
4 |
Correct |
0 ms |
1304 KB |
Output is correct |
5 |
Correct |
0 ms |
1312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1304 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2188 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2184 KB |
Output is correct |
2 |
Correct |
0 ms |
2196 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |