結果

問題 No.3 ビットすごろく
ユーザー airuaiairuai
提出日時 2016-09-14 02:06:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 55,640 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2024-04-28 13:20:25
合計ジャッジ時間 13,472 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 78 ms
11,244 KB
testcase_06 AC 7 ms
6,996 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 AC 29 ms
11,228 KB
testcase_09 AC 486 ms
11,148 KB
testcase_10 WA -
testcase_11 AC 295 ms
11,192 KB
testcase_12 AC 63 ms
11,176 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 962 ms
11,248 KB
testcase_15 AC 958 ms
11,280 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 5 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 955 ms
11,156 KB
testcase_23 AC 954 ms
11,260 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 6 ms
6,940 KB
testcase_28 WA -
testcase_29 AC 310 ms
11,108 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 191 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

#define MAX 1000000

int q[MAX][2];
int head = 0, tail = 0;

void enq(int p, int kind) {
	q[tail][0] = p;
	q[tail][1] = kind;
	++tail;
	if (tail >= MAX) {
		tail = 0;
	}
}

bool deq(int* p, int* kind) {
	if (head == tail) {
		return false;
	}
	else {
		*p = q[head][0];
		*kind = q[head][1];
		++head;
		if (head >= MAX) {
			head = 0;
		}
		return true;
	}
}

int BinaryCount(int n) {
	int count = 0;
	while (n > 0) {
		count += n % 2;
		n /= 2;
	}
	return count;
}

int main(void) {
	int n;
	cin >> n;
	
	bool* flag = new bool[n];
	for (int i = 0; i < n; ++i) {
		flag[i] = false;
	}

	int posi = 1, hosuu;
	int kind = 1;
	do {
		if (posi == n) {
			cout << kind << endl;
			return 0;
		}

		flag[posi - 1] = true;
		hosuu = BinaryCount(posi);
		if (posi - hosuu > 0 && !flag[posi - 1 - hosuu]) {
			enq(posi - hosuu, kind + 1);
		}
		if (posi + hosuu <= n && !flag[posi - 1 + hosuu]) {
			enq(posi + hosuu, kind + 1);
		}
	} while (deq(&posi, &kind));

	cout << "-1" << endl;

	return 0;
}
0