結果

問題 No.3 ビットすごろく
ユーザー aim_cpoaim_cpo
提出日時 2017-05-04 01:53:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,523 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 88,520 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 08:06:20
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
//#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
bool b[10001];
int ans = 0;
void solve(int a) {
	if (a == n)return;
	if (b[a] == 1) {
		ans = inf;
		return;
	}
	b[a] = 1;
	ans++;
	int i = 1;
	int keta = 1;
	while (1) {
		if (i == a)break;
		if (i > a) { keta--; break; }
		i *= 2;
		keta++;
	}
	int cont = 0;
	int aa = a;
	while (a>0) {
		if (a / i > 0) {
			cont++; a %= i;
		}
		i /= 2;
	}
	if (aa + cont <= n) {
		solve(aa + cont);
	}
	else {
		solve(aa - cont);
	}
	return;
}

int main() {
	cin >> n;
	solve(1);
	if (ans == inf) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans+1 << endl;
	return 0;
}
0