結果

問題 No.3 ビットすごろく
ユーザー yukiteruyukiteru
提出日時 2018-02-10 10:21:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,016 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 87,640 KB
実行使用メモリ 652,084 KB
最終ジャッジ日時 2024-04-20 22:13:56
合計ジャッジ時間 64,979 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

using namespace std;
typedef pair<int, int> P;

int main(void) {
	int n;
	queue<P>que;

	cin >> n;

	que.push(P(1,1));
	while (1) {
		int a, deep;
		int b;
		int flag = 0;
		a = que.front().first;
		deep = que.front().second;
		b = a;
		if (deep > 30) {
			cout << -1 << endl;
			break;
		}
		que.pop();
		while (1) {
			if (b % 2 == 1) {
				flag++;
			}
			b /= 2;
			if (b == 0) {
				break;
			}
		}
		if (a + flag == n) {
			cout << deep + 1 << endl;
			break;
		}
		if (a - flag > 0) {
			que.push(P(a - flag, deep + 1));
		}
		if (a + flag < n) {
			que.push(P(a + flag, deep + 1));
		}
		
	}


	
	return 0;
}
0