結果

問題 No.3 ビットすごろく
ユーザー newlife171128newlife171128
提出日時 2017-12-21 21:37:11
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 653 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 65,112 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 22:40:34
合計ジャッジ時間 1,593 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

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

	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;

	dfs(1, 0);

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