結果

問題 No.3 ビットすごろく
ユーザー newlife171128newlife171128
提出日時 2017-12-21 22:05:28
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 64,724 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 22:46:02
合計ジャッジ時間 23,972 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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] != 0) {
		cout << nums[n] << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}

0