Submission #19365176


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 500005 
 
int x, y;

int MEM(int cur, map<int,int> &dp)
{
    //cout << cur << endl;
    if(cur<=x)
        return x-cur;

    if(dp.count(cur))
        return dp.at(cur);

    int ans = cur-x;


    if(cur%2==0)
        ans = min(ans, 1 + MEM(cur/2, dp));
    else
    {
        ans = min(ans, 2 + MEM((cur-1)/2, dp));
        ans = min(ans, 2 + MEM((cur+1)/2, dp));
    }

    dp[cur] = ans;
    return ans;
}
 
int32_t main()
{

 
    
    int t = 1;
    while(t--)
    {
        
        cin >> x >> y;
        if(y<=x)
            cout << x-y;
        else
        {
            map<int, int> dp;
            cout << MEM(y, dp) << endl;
        }
    }



   
 
    return 0;
}

Submission Info

Submission Time
Task F - +1-1x2
User pawan_asipu
Language C++ (GCC 9.2.1)
Score 600
Code Size 895 Byte
Status AC
Exec Time 6 ms
Memory 3660 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 600 / 600 0 / 0
Status
AC × 3
AC × 49
AC × 1
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, extreme_04.txt, handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_03.txt, handmade_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_exp_00.txt, random_exp_01.txt, random_exp_02.txt, random_exp_03.txt, random_exp_04.txt, random_exp_05.txt, random_exp_06.txt, random_exp_07.txt, random_exp_08.txt, random_exp_09.txt, random_exp_10.txt, random_exp_11.txt, random_exp_12.txt, random_exp_13.txt, random_exp_14.txt, random_exp_15.txt, random_small_00.txt, random_small_01.txt, random_small_02.txt, random_small_03.txt, random_small_04.txt, random_small_05.txt, random_small_06.txt, random_small_07.txt, random_small_08.txt, random_small_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
after_contest after_contest_01.txt
Case Name Status Exec Time Memory
after_contest_01.txt AC 6 ms 3536 KB
extreme_00.txt AC 3 ms 3488 KB
extreme_01.txt AC 2 ms 3660 KB
extreme_02.txt AC 2 ms 3540 KB
extreme_03.txt AC 3 ms 3564 KB
extreme_04.txt AC 2 ms 3608 KB
handmade_00.txt AC 2 ms 3600 KB
handmade_01.txt AC 2 ms 3656 KB
handmade_02.txt AC 4 ms 3656 KB
handmade_03.txt AC 3 ms 3640 KB
handmade_04.txt AC 2 ms 3480 KB
random_00.txt AC 2 ms 3632 KB
random_01.txt AC 3 ms 3532 KB
random_02.txt AC 2 ms 3604 KB
random_03.txt AC 5 ms 3424 KB
random_04.txt AC 4 ms 3560 KB
random_05.txt AC 3 ms 3508 KB
random_06.txt AC 2 ms 3500 KB
random_07.txt AC 3 ms 3432 KB
random_08.txt AC 2 ms 3532 KB
random_09.txt AC 2 ms 3508 KB
random_exp_00.txt AC 2 ms 3600 KB
random_exp_01.txt AC 2 ms 3432 KB
random_exp_02.txt AC 3 ms 3560 KB
random_exp_03.txt AC 2 ms 3632 KB
random_exp_04.txt AC 3 ms 3640 KB
random_exp_05.txt AC 2 ms 3604 KB
random_exp_06.txt AC 2 ms 3552 KB
random_exp_07.txt AC 2 ms 3528 KB
random_exp_08.txt AC 2 ms 3600 KB
random_exp_09.txt AC 3 ms 3580 KB
random_exp_10.txt AC 2 ms 3504 KB
random_exp_11.txt AC 2 ms 3604 KB
random_exp_12.txt AC 3 ms 3556 KB
random_exp_13.txt AC 2 ms 3604 KB
random_exp_14.txt AC 3 ms 3460 KB
random_exp_15.txt AC 2 ms 3552 KB
random_small_00.txt AC 2 ms 3600 KB
random_small_01.txt AC 2 ms 3504 KB
random_small_02.txt AC 2 ms 3588 KB
random_small_03.txt AC 2 ms 3528 KB
random_small_04.txt AC 2 ms 3556 KB
random_small_05.txt AC 3 ms 3496 KB
random_small_06.txt AC 4 ms 3656 KB
random_small_07.txt AC 2 ms 3456 KB
random_small_08.txt AC 2 ms 3580 KB
random_small_09.txt AC 3 ms 3432 KB
sample_01.txt AC 2 ms 3428 KB
sample_02.txt AC 5 ms 3496 KB
sample_03.txt AC 2 ms 3532 KB