Submission #930202

# Submission time Handle Problem Language Result Execution time Memory
930202 2024-02-19T01:26:47 Z ezzzay Board (CEOI13_board) C++14
40 / 100
15 ms 2132 KB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
map<int,int>dist;
string a,b;

signed main(){
    cin>>a;
    int x=1;
    int y=1;
    int lvl=1;
    dist[1]=1;
    for(auto c:a){
        if(c=='1'){
            x*=2;
            lvl++;
        }
        else if(c=='2'){
            x=x*2+1;
            lvl++;
        }
        else if(c=='U'){
            x=x/2;
            lvl--;
        }
        else if(c=='L'){
            x--;
        }
        else{
            x++;
        }
        dist[x]=lvl;
    }
    lvl=1;
    cin>>a;
    for(auto c:a){
        if(c=='1'){
            y*=2;
            lvl++;
        }
        else if(c=='2'){
            y=y*2+1;
            lvl++;
        }
        else if(c=='U'){
            y=y/2;
            lvl--;
        }
        else if(c=='L'){
            y--;
        }
        else{
            y++;
        }
        dist[y]=lvl;
    }
   
    if(dist[y]>dist[x]){
        swap(y,x);
    }
    int k=0;
    int p=dist[x];
    while(dist[x]>dist[y]){
        x=x/2;
        dist[x]= --p;
        k++;
    }
    int ans=k+abs(x-y);
     p=dist[x];
    while(p>1){
        x=x/2;
        y=y/2;
        p--;
        k+=2;
        ans=min(ans,k+abs(x-y));
    }
    cout<<ans;
}
# 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 8 ms 604 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
# 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 3 ms 860 KB Output is correct
2 Correct 15 ms 2132 KB Output is correct
3 Correct 7 ms 1296 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1128 KB Output isn't correct
2 Halted 0 ms 0 KB -