結果

問題 No.3 ビットすごろく
ユーザー newlife171128
提出日時 2017-12-21 22:06:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3,021 ms / 5,000 ms
コード長 852 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 64,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 08:54:27
合計ジャッジ時間 25,831 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;

int nums[10001] = {10000};
int n = 0;
void dfs(int x, int times) {
	if (x > n || x < 1 || times+1>nums[x]) {
		return;
	}

/*
	if (nums[x] != 0 && ++times < nums[x]) {
		nums[x] = ++times;
	}
	if (nums[x] == 0) {
		nums[x] = ++times;
	}
*/

	nums[x] = min(nums[x],++times);
/*


	 cout << "nums:" << x << " " << times << endl;
*/

/*	 cout<<nums[x]<<endl;*/


	int count = 0;
	for (int k = 0; k <= /* ceil(sqrt(i))*/log2(x); k++) {
		if ((x >> k) % 2 == 1) {
			count++;
		}
	}
	dfs(x + count, times);

	dfs(x - count, times);

}
int main() {

	cin >> n;

	for(int i=1; i<=n; i++){
		nums[i] =10000;
	}

	dfs(1, 0);

	if (nums[n] != 10000) {
		cout << nums[n] << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}
0