Submission #19358952


Source Code Expand

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_ll.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
map<ll,ll> m1;
ll func(ll x,ll y){
  if(m1.find(y)!=m1.end()) return m1[y];
  if(x>=y) return x-y;
  ll ans=y-x;
  if(y%2) ans=min({ans,2+func(x,(y-1)/2),2+func(x,(y+1)/2)});
  else ans=min(ans,1+func(x,y/2));
  return m1[y]=ans;
}
void solve(){
  ll x,y;
  cin>>x>>y;
  cout<<func(x,y)<<endl;
}

int32_t main(){
    optimizeIO();
    ll r=1;
    {solve();}
}

Submission Info

Submission Time
Task F - +1-1x2
User vineetjai
Language C++ (GCC 9.2.1)
Score 600
Code Size 1241 Byte
Status AC
Exec Time 6 ms
Memory 3612 KiB

Compile Error

./Main.cpp: In function ‘int32_t main()’:
./Main.cpp:50:8: warning: unused variable ‘r’ [-Wunused-variable]
   50 |     ll r=1;
      |        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 49
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
Case Name Status Exec Time Memory
extreme_00.txt AC 2 ms 3520 KiB
extreme_01.txt AC 2 ms 3540 KiB
extreme_02.txt AC 2 ms 3552 KiB
extreme_03.txt AC 4 ms 3576 KiB
extreme_04.txt AC 2 ms 3568 KiB
handmade_00.txt AC 3 ms 3492 KiB
handmade_01.txt AC 3 ms 3604 KiB
handmade_02.txt AC 2 ms 3536 KiB
handmade_03.txt AC 2 ms 3560 KiB
handmade_04.txt AC 2 ms 3504 KiB
random_00.txt AC 1 ms 3432 KiB
random_01.txt AC 6 ms 3492 KiB
random_02.txt AC 2 ms 3508 KiB
random_03.txt AC 2 ms 3552 KiB
random_04.txt AC 2 ms 3488 KiB
random_05.txt AC 1 ms 3428 KiB
random_06.txt AC 2 ms 3560 KiB
random_07.txt AC 3 ms 3488 KiB
random_08.txt AC 3 ms 3552 KiB
random_09.txt AC 2 ms 3428 KiB
random_exp_00.txt AC 3 ms 3432 KiB
random_exp_01.txt AC 2 ms 3600 KiB
random_exp_02.txt AC 5 ms 3544 KiB
random_exp_03.txt AC 2 ms 3488 KiB
random_exp_04.txt AC 2 ms 3436 KiB
random_exp_05.txt AC 2 ms 3508 KiB
random_exp_06.txt AC 2 ms 3540 KiB
random_exp_07.txt AC 2 ms 3552 KiB
random_exp_08.txt AC 2 ms 3604 KiB
random_exp_09.txt AC 2 ms 3504 KiB
random_exp_10.txt AC 2 ms 3508 KiB
random_exp_11.txt AC 2 ms 3496 KiB
random_exp_12.txt AC 2 ms 3504 KiB
random_exp_13.txt AC 2 ms 3504 KiB
random_exp_14.txt AC 2 ms 3612 KiB
random_exp_15.txt AC 2 ms 3484 KiB
random_small_00.txt AC 3 ms 3448 KiB
random_small_01.txt AC 2 ms 3508 KiB
random_small_02.txt AC 2 ms 3608 KiB
random_small_03.txt AC 2 ms 3488 KiB
random_small_04.txt AC 2 ms 3604 KiB
random_small_05.txt AC 2 ms 3540 KiB
random_small_06.txt AC 3 ms 3488 KiB
random_small_07.txt AC 2 ms 3552 KiB
random_small_08.txt AC 3 ms 3548 KiB
random_small_09.txt AC 2 ms 3492 KiB
sample_01.txt AC 2 ms 3556 KiB
sample_02.txt AC 2 ms 3600 KiB
sample_03.txt AC 2 ms 3508 KiB