結果

問題 No.3 ビットすごろく
ユーザー めうめう🎒めうめう🎒
提出日時 2016-01-22 18:59:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 980 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 23:38:51
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
4,376 KB
testcase_01 AC 33 ms
4,376 KB
testcase_02 AC 32 ms
4,380 KB
testcase_03 AC 33 ms
4,376 KB
testcase_04 AC 32 ms
4,380 KB
testcase_05 AC 36 ms
4,376 KB
testcase_06 AC 33 ms
4,380 KB
testcase_07 AC 32 ms
4,380 KB
testcase_08 AC 34 ms
4,380 KB
testcase_09 AC 50 ms
4,376 KB
testcase_10 AC 80 ms
4,376 KB
testcase_11 AC 43 ms
4,380 KB
testcase_12 AC 35 ms
4,380 KB
testcase_13 AC 33 ms
4,380 KB
testcase_14 AC 71 ms
4,376 KB
testcase_15 AC 138 ms
4,380 KB
testcase_16 AC 97 ms
4,376 KB
testcase_17 AC 129 ms
4,376 KB
testcase_18 AC 33 ms
4,380 KB
testcase_19 AC 152 ms
4,380 KB
testcase_20 AC 33 ms
4,376 KB
testcase_21 AC 32 ms
4,376 KB
testcase_22 AC 73 ms
4,380 KB
testcase_23 AC 151 ms
4,376 KB
testcase_24 AC 152 ms
4,380 KB
testcase_25 AC 140 ms
4,380 KB
testcase_26 AC 32 ms
4,376 KB
testcase_27 AC 33 ms
4,376 KB
testcase_28 AC 93 ms
4,380 KB
testcase_29 AC 44 ms
4,376 KB
testcase_30 AC 32 ms
4,380 KB
testcase_31 AC 33 ms
4,376 KB
testcase_32 AC 40 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;

#define INF (1 << 30)
#define INFLL (1LL << 60)

int ido[10010] = {},n;

int bit_how(int n){
	stringstream ss;
	ss << bitset<32>(n);
	int ans = 0;
	for(int i = 0;i < ss.str().size();i++){
		if(ss.str()[i] == '1') ans++;
	}
	return ans;
}

int memo[10010] = {};

int saiki(int now,int how){
	if(memo[now] < how) return INF;
	if(now > n) return INF;
	if(now == n) return how;
	int a,b;
	memo[now] = how;
	a = saiki(now + ido[now],how+1);
	b = saiki(now - ido[now],how+1);
	return min(a,b);
}

int main() {
	int how;
	for(int i = 0;i < 10010;i++) memo[i] = INF;
	for(int i = 0;i < 10010;i++){
		ido[i] = bit_how(i);
	}
	cin >> n;
	int ans = saiki(1,1);
	if(ans == INF) cout << "-1" << endl;
	else cout << ans << endl;
	return 0;
}
0