Submission #931102

# Submission time Handle Problem Language Result Execution time Memory
931102 2024-02-21T08:34:59 Z batsukh2006 Board (CEOI13_board) C++17
40 / 100
2 ms 976 KB
#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

board.cpp: In function 'void solve()':
board.cpp:38:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0; i<a.size(); i++){
      |                  ~^~~~~~~~~
board.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<b.size(); i++){
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 516 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -