Submission #50898

#TimeUsernameProblemLanguageResultExecution timeMemory
50898tmwilliamlin168Board (CEOI13_board)C++14
100 / 100
122 ms2180 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...