Submission #2925513


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int ans;

void dfs(int s, int t, int cnt) {
	//cout << s << " " << t << " " << cnt << endl;
	if(s == t){
		ans = cnt; 	
		return ;
	}
	if(s > t) return ;
	dfs(s * 2, t, cnt + 1);
	dfs(s * 2 + 1, t, cnt + 1);
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	
	#ifdef LOCAL_DEFINE
	freopen("input.txt", "rt", stdin);
	#endif

	int n, s, t;
	cin >> n >> s >> t;

	if(s == t){
		cout << 0 << endl;
		return 0;
	}

	dfs(s, t, 0);

	cout << (ans == 0 ? -1 : ans) << endl;	                            
 	                              
	#ifdef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s. \n";
	#endif 

	return 0;
}

Submission Info

Submission Time
Task B - Camphor Tree
User Impulse
Language C++14 (GCC 5.4.1)
Score 100
Code Size 744 Byte
Status AC
Exec Time 136 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 13
Set Name Test Cases
All 00_sample, 01_sample, 02_sample, max_01, max_02, max_03, max_04, max_05, max_06, max_07, max_08, max_09, min_00
Case Name Status Exec Time Memory
00_sample AC 1 ms 256 KB
01_sample AC 1 ms 256 KB
02_sample AC 1 ms 256 KB
max_01 AC 136 ms 256 KB
max_02 AC 1 ms 256 KB
max_03 AC 1 ms 256 KB
max_04 AC 1 ms 256 KB
max_05 AC 1 ms 256 KB
max_06 AC 1 ms 256 KB
max_07 AC 1 ms 256 KB
max_08 AC 1 ms 256 KB
max_09 AC 1 ms 256 KB
min_00 AC 1 ms 256 KB