結果

問題 No.3 ビットすごろく
ユーザー kaffelunkaffelun
提出日時 2017-09-27 22:21:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 165 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 144,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:49:47
合計ジャッジ時間 3,644 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define INF 2000000000

int BitCount(int64_t x) {
	x = (x & 0x5555555555555555) + (x >>  1 & 0x5555555555555555);
	x = (x & 0x3333333333333333) + (x >>  2 & 0x3333333333333333);
	x = (x & 0x0f0f0f0f0f0f0f0f) + (x >>  4 & 0x0f0f0f0f0f0f0f0f);
	x = (x & 0x00ff00ff00ff00ff) + (x >>  8 & 0x00ff00ff00ff00ff);
	x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
	x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff);
	return (int)(x);
}

int N;
int x[10000];

void recursive(int pos, int t) {
	if(pos < 0 || pos > N) return;
	if(x[pos] < t) return;
	else x[pos] = t; 
	int d = BitCount(pos + 1);
	recursive(pos + d, t + 1);
	recursive(pos - d, t + 1);
}

int main() {
	cin >> N;
	for(int i = 0; i < N; i++) {
		x[i] = INF;
	}
	recursive(0, 0);
	if(x[N - 1] == INF) x[N - 1] = -2;
	cout << x[N - 1] + 1 << endl;
	return 0;
}
0