結果

問題 No.3 ビットすごろく
ユーザー memedosagememedosage
提出日時 2017-06-22 17:21:28
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 729 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 72,128 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2024-04-10 10:30:10
合計ジャッジ時間 3,835 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int recursive(int, int, int, int, std::unordered_map<int, int>&)’:
main.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
   30 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <unordered_map>
#include <vector>

int numofbits(int number) {
	int a=0;
	for (; number!=0; number&=number-1) {
		a++;
	}
	return a;
}

int recursive(int now, int prev, int n, int step, std::unordered_map<int,int> &alr) {
	int bit = numofbits(now);
	if (now + bit == n) {
		step++;
		return step;
	} else if (now + bit > n) {
		step++;
		if (alr.find(now-bit) != alr.end()) {
			return -1;
		}
		alr[now] = 1;
		recursive(now-bit, now, n, step, alr);
	} else if (now + bit < n) {
		step++;
		alr[now] = 1;
		recursive(now+bit, now, n, step, alr);
	}
}

int main() {
	int n;
	std::cin >> n;


	std::unordered_map<int,int> alr;
	int step = recursive(1, 1, n, 1, alr);
	std::cout << step << std::endl;
}
0