This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
set<int> pre;
string s, t;
bool type;
int p, x;
void flip(int p){
if (pre.count(p)) pre.erase(p);
else pre.insert(p);
}
string con(string S){
type=0; p=0; pre.clear();
fox(l, S.size()){
if (S[l]=='1' && type){
type=0;
pre.insert(p);
}
if (S[l]=='2' && !type){
type=1;
pre.insert(p);
}
if (S[l]=='1' || S[l]=='2') p++;
if (S[l]=='U'){
--p;
if (pre.count(p)){
type=!type;
pre.erase(p);
}
}
if (S[l]=='L'){
if (type){
flip(p-1);
} else {
x=*--pre.end();
flip(--x);
}
type=!type;
}
if (S[l]=='R'){
if (!type){
flip(p-1);
} else {
x=*--pre.end();
flip(--x);
}
type=!type;
}
}
type=0;
S="";
//cout << p << endl;
fox(l, p){
if (pre.count(l)) type=!type;
S+=char(type+'0');
}
return S;
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cin >> s;
s=con(s);
cin >> t;
t=con(t);
//cout << s << ' ' << endl << t << endl;
ll a=0, b=0;
int ans=(1 << 30);
fox(l, min(s.size(), t.size())){
a=a*2+s[l]-'0';
b=b*2+t[l]-'0';
if (abs(b-a)>400000) break;
//cout << a << ' ' << b << endl;
ans=min(ans, int(abs(a-b)+s.size()+t.size()-l*2-2));
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
board.cpp: In function 'std::__cxx11::string con(std::__cxx11::string)':
board.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
board.cpp:37:5: note: in expansion of macro 'fox'
fox(l, S.size()){
^
board.cpp: In function 'int main()':
board.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
board.cpp:92:5: note: in expansion of macro 'fox'
fox(l, min(s.size(), t.size())){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |