結果

問題 No.3 ビットすごろく
ユーザー tokutoku
提出日時 2019-03-18 22:01:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 147,152 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-26 10:48:34
合計ジャッジ時間 3,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,384 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		



vector<bool> used(10050, false);
VI v(10050,0);
VI ans(10050, INF);
int n;

void dfs(int m,int k) {
	ans[m] = min(ans[m], k);
	if (used[m]) return;
	used[m] = true;
	if (m - v[m] > 0)dfs(m - v[m], k + 1);
	if (m + v[m] <= n)dfs(m + v[m], k + 1);
	return;
}

int main() {


	cin >> n;


	FOR(i, 1, 10001) {
		int j = i;
		while (j) {
			v[i] += j % 2;
			j /= 2;
		}
	}

	dfs(1, 1);

	if (ans[n] == INF)cout << -1 << endl;
	else cout << ans[n] << endl;

	return 0;

}
0