#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;
vector<int> parse(string s) {
deque<pair<bool, int>> res;
res.push_back({1, 1});
int sz = 1;
for (char c : s) {
if (c == '1') {
if (!res.back().first) {
res.back().second++;
}
else {
res.push_back({0, 1});
}
sz++;
}
else if (c == '2') {
if (res.back().first) {
res.back().second++;
}
else {
res.push_back({1, 1});
}
sz++;
}
else if (c == 'U') {
res.back().second--;
if (res.back().second==0) {
res.pop_back();
}
sz--;
}
else if (c == 'L') {
if (res.back().first == 1) {
res.back().second--;
if (res.back().second == 0) {
res.pop_back();
res.back().second++;
}
else {
res.push_back({0, 1});
}
}
else {
int lst = res.back().second;
res.pop_back();
res.back().second--;
if (res.back().second == 0) {
res.pop_back();
res.back().second++;
}
else {
res.push_back({0, 1});
}
res.push_back({1, lst});
}
}
else if (c == 'R') {
if (res.back().first == 0) {
res.back().second--;
if (res.back().second == 0) {
res.pop_back();
res.back().second++;
}
else {
res.push_back({1, 1});
}
}
else {
int lst = res.back().second;
res.pop_back();
res.back().second--;
if (res.back().second == 0) {
res.pop_back();
res.back().second++;
}
else {
res.push_back({1, 1});
}
res.push_back({0, lst});
}
}
}
vector<int> ret(sz);
int cur = sz;
while (res.size()) {
FR(iter, res.back().second) {
ret[--cur] = res.back().first;
}
res.pop_back();
}
return ret;
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
string A;
string B;
cin >> A >> B;
vector<int> sA = parse(A);
vector<int> sB = parse(B);
if (sA.size() < sB.size()) {
swap(sA, sB);
}
int d = 0;
while (sA.size() > sB.size()) {
sA.pop_back();
d++;
}
if (sA > sB) {
swap(sA, sB);
}
int res = (int)(1e9);
int diff = 0;
for (int k = 0; k < sA.size(); k++) {
diff *= 2;
diff += sB[k]-sA[k];
if (diff >= 100) {
break;
}
res = min((int(sA.size())-k-1)*2+d+diff, res);
}
cout << res << '\n';
return 0;
}
Compilation message
board.cpp: In function 'int main()':
board.cpp:121:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for (int k = 0; k < sA.size(); k++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
748 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
5 ms |
748 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1132 KB |
Output is correct |
2 |
Correct |
4 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1132 KB |
Output is correct |
2 |
Correct |
4 ms |
1260 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1004 KB |
Output is correct |
2 |
Correct |
4 ms |
1260 KB |
Output is correct |
3 |
Correct |
3 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
1260 KB |
Output is correct |