# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
931102 | batsukh2006 | Board (CEOI13_board) | C++17 | 2 ms | 976 KiB |
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<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define int long long
#define endl '\n'
int log(int x) {
int sum=0;
while(x>1){
sum++;
x/=2;
}
return sum;
}
void solve(){
string a,b; cin>>a>>b;
int f=1,s=1;
for(int i=0; i<a.size(); i++){
if(a[i]=='1') f=f*2;
if(a[i]=='2') f=f*2+1;
if(a[i]=='U') f=f/2;
if(a[i]=='L') f=f-1;
if(a[i]=='R') f=f+1;
}
for(int i=0; i<b.size(); i++){
if(b[i]=='1') s=s*2;
if(b[i]=='2') s=s*2+1;
if(b[i]=='U') s=s/2;
if(b[i]=='L') s=s-1;
if(b[i]=='R') s=s+1;
}
if(log(f)>log(s)) swap(f,s);
int diff=log(s)-log(f);
int sum=diff;
while(diff--) s/=2;
int ans=sum+abs(f-s);
int cur=log(f);
while(cur--){
sum+=2;
f/=2;
s/=2;
ans=min(ans,sum+abs(f-s));
}
cout<<ans;
}
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
// cin>>T;
while(T--){
solve();
cout<<endl;
}
return 0;
}
Compilation message (stderr)
# | 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... |