結果

問題 No.3 ビットすごろく
ユーザー memmemmimemmemmi
提出日時 2018-06-22 15:45:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 979 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 94,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 01:03:20
合計ジャッジ時間 2,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int bitCnt(int x) {
	int cnt = 0;
	for (int i = 0; i < 14; i++) {
		if (x & 1 << i)cnt++;
	}
	return cnt;
}

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

	vector <int> check(n + 1, INT_MAX);
	queue<int> c;
	check[1] = 1;

	c.push(1);

	while (!c.empty()) {
		int p = c.front(); c.pop();
		int d = bitCnt(p);

		for (int i = -d; i <= d; i += 2 * d) {
			int np = p + i;
			if (np<1 || np>n)continue;
			if (check[np] != INT_MAX)continue;
			check[np] = check[p] + 1;
			c.push(np);
		}
	}

	cout << ((check[n] == INT_MAX) ? (-1) : check[n]) << endl;

	return 0;
}
0