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
const int mxD=1e5, bs=62, mxBC=mxD/bs+1;
int sa, sb, ans=2*mxD, a1=0;
ll bva[mxBC], bvb[mxBC];
inline void rd(ll *bv, int &s) {
bv[0]=1LL<<(bs-1);
s=1;
string ms;
cin >> ms;
for(char c : ms) {
if(c=='1') {
bv[s/bs]&=~(1LL<<(bs-1-s%bs));
++s;
} else if(c=='2') {
bv[s/bs]|=1LL<<(bs-1-s%bs);
++s;
} else if(c=='L') {
bv[(s-1)/bs]-=1LL<<(bs-1-(s-1)%bs);
for(int i=(s-1)/bs; bv[i]<0; --i) {
bv[i]+=1LL<<bs;
--bv[i-1];
}
} else if(c=='R') {
bv[(s-1)/bs]+=1LL<<(bs-1-(s-1)%bs);
for(int i=(s-1)/bs; bv[i]>=1LL<<bs; --i) {
bv[i]-=1LL<<bs;
++bv[i-1];
}
} else
--s;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
rd(bva, sa);
rd(bvb, sb);
// cout << bva[0] << " " << bvb[0] << endl;
for(int i=0; i<min(sa, sb)&&abs(a1)<=ans; ++i) {
a1=2*a1+(bva[i/bs]>>(bs-1-i%bs)&1)-(bvb[i/bs]>>(bs-1-i%bs)&1);
// cout << i << " " << a1 << endl;
ans=min(abs(a1)+sa-i+sb-i-2, ans);
}
cout << ans;
}
# | 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... |