Submission #19339330


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll X,Y;

map<ll,ll> M;

ll dfs(ll v) {
	if(M.count(v)) return M[v];
	if(v<=X) return M[v]=X-v;
	M[v]=v-X;
	if(v%2==0) {
		M[v]=min(M[v],1+dfs(v/2));
	}
	else {
		M[v]=min(M[v],2+dfs((v+1)/2));
		M[v]=min(M[v],2+dfs((v-1)/2));
	}
	return M[v];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y;
	if(Y<=X) {
		cout<<X-Y<<endl;
		return;
	}
	cout<<dfs(Y)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task F - +1-1x2
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 1227 Byte
Status AC
Exec Time 7 ms
Memory 3588 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:35:6: warning: unused variable ‘i’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |      ^
./Main.cpp:35:8: warning: unused variable ‘j’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:35:10: warning: unused variable ‘k’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:35:12: warning: unused variable ‘l’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:35:14: warning: unused variable ‘r’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:35:16: warning: unused variable ‘x’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |                ^
./Main.cpp:35:18: warning: unused variable ‘y’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:50:38: note: in expansion of macro ‘FOR’
   50 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

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 7 ms 3568 KB
extreme_01.txt AC 2 ms 3536 KB
extreme_02.txt AC 2 ms 3548 KB
extreme_03.txt AC 2 ms 3428 KB
extreme_04.txt AC 2 ms 3496 KB
handmade_00.txt AC 2 ms 3524 KB
handmade_01.txt AC 3 ms 3416 KB
handmade_02.txt AC 2 ms 3488 KB
handmade_03.txt AC 2 ms 3484 KB
handmade_04.txt AC 2 ms 3536 KB
random_00.txt AC 2 ms 3520 KB
random_01.txt AC 2 ms 3484 KB
random_02.txt AC 2 ms 3420 KB
random_03.txt AC 1 ms 3416 KB
random_04.txt AC 2 ms 3504 KB
random_05.txt AC 3 ms 3524 KB
random_06.txt AC 2 ms 3500 KB
random_07.txt AC 2 ms 3520 KB
random_08.txt AC 3 ms 3516 KB
random_09.txt AC 2 ms 3568 KB
random_exp_00.txt AC 2 ms 3576 KB
random_exp_01.txt AC 2 ms 3484 KB
random_exp_02.txt AC 2 ms 3532 KB
random_exp_03.txt AC 3 ms 3576 KB
random_exp_04.txt AC 2 ms 3500 KB
random_exp_05.txt AC 6 ms 3484 KB
random_exp_06.txt AC 4 ms 3588 KB
random_exp_07.txt AC 2 ms 3572 KB
random_exp_08.txt AC 2 ms 3524 KB
random_exp_09.txt AC 2 ms 3528 KB
random_exp_10.txt AC 3 ms 3572 KB
random_exp_11.txt AC 2 ms 3460 KB
random_exp_12.txt AC 3 ms 3488 KB
random_exp_13.txt AC 2 ms 3524 KB
random_exp_14.txt AC 2 ms 3540 KB
random_exp_15.txt AC 2 ms 3524 KB
random_small_00.txt AC 2 ms 3504 KB
random_small_01.txt AC 3 ms 3476 KB
random_small_02.txt AC 2 ms 3464 KB
random_small_03.txt AC 3 ms 3568 KB
random_small_04.txt AC 3 ms 3528 KB
random_small_05.txt AC 2 ms 3576 KB
random_small_06.txt AC 3 ms 3484 KB
random_small_07.txt AC 2 ms 3528 KB
random_small_08.txt AC 2 ms 3524 KB
random_small_09.txt AC 4 ms 3460 KB
sample_01.txt AC 2 ms 3496 KB
sample_02.txt AC 2 ms 3460 KB
sample_03.txt AC 2 ms 3540 KB