#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<int, int> point;
vector <int> a, b;
string sa, sb;
const int off = 1 << 17;
void update(string &s, vector <int> &v){
for(auto it : s){
if(it == '1')
v.pb(0);
else if(it == '2')
v.pb(1);
else if(it == 'L')
v.back() --;
else if(it == 'R')
v.back() ++;
else{
int x = v.back();
v.pop_back();
if(x >= 0){
v.back() += x / 2;
}
else{
v.back() += x / 2;
x -= x / 2 * 2;
if(x < 0){
v.back() --;
}
}
}
}
}
void prop(vector <int> &v){
for(int i = sz(v) - 1; i > 0; --i){
int x = v[i];
if(x >= 0){
v[i - 1] += v[i] / 2;
v[i] %= 2;
}
else{
v[i - 1] += v[i] / 2;
v[i] -= v[i] / 2 * 2;
if(v[i] < 0){
v[i - 1] --;
v[i] += 2;
}
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> sa >> sb;
update(sa, a);
update(sb, b);
prop(a); prop(b);
ll tmp = sz(a) + sz(b), dist = 0, sol = 1e16;
REP(i, min(sz(a), sz(b))){
dist <<= 1;
dist += abs(a[i] - b[i]);
tmp -= 2;
sol = min(sol, tmp + dist);
if(dist > 1e14)
break;
}
cout << sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Incorrect |
3 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
528 KB |
Output is correct |
2 |
Incorrect |
5 ms |
760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1396 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1524 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |