結果

問題 No.3 ビットすごろく
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-04-10 00:58:01
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,527 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 27,724 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-25 01:33:44
合計ジャッジ時間 4,706 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define READ_BUFSIZE ( 16 )
#define READ_DELIMITER ( " " )


//標準入力取得(1行)

int GetStdin( char* pszStr, int lMaxLen )
{
	int lLen = 0;

    memset( pszStr, 0, lMaxLen );
    if( fgets( pszStr, lMaxLen, stdin ) )
    {
	    lLen = strlen( pszStr );
	    if( lLen >= 1 )
	    {
			if( pszStr[ lLen - 1 ] == 0x0A )
			{
				pszStr[ lLen - 1 ] = 0;
				lLen--;
			}
		}
	}
	
	return( lLen );
}

int bit( int value )
{
	int count = 0;

	for( int i = 1; i <= 10000; i*=2 )
	{
		if( ( value & i ) == i )
			count++;
	}

	return count;

}

//P : 今いる場所 最初1
//N:目的値
//c:これまでの移動回数
//map:通ってきた道
//count Nに到達して中で最小の値

int main(int argc, char *argv[]) 
{
	char szRead[READ_BUFSIZE] = "";
	//char* psOutbuf[10000] = { 0 };
	int lInput[4] = {0};

	GetStdin( szRead, READ_BUFSIZE );

	int N = atoi( szRead );


	int Q[10000][2]={0};
	int count = 1;

	int P = 1; //今いる場所
	int i = -1; //追加するキューのシーケンス
	int j = 0;
	char map[10000] = {0};
	int ido = 0;

	map[1] = 1;
	for( ; P < N;  j++ )
	{
		ido = bit( P );
		if( P + ido <= N && map[P + ido] == 0 )
		{
			i++;
			Q[i][0] = P+ ido;
			Q[i][1] = count+1;
		}

		if( P - ido > 0 && map[P - ido] == 0)
		{
			i++;
			Q[i][0] = P - ido;
			Q[i][1] = count+1;
		}

		if( Q[j][0] == 0 )
			break;

		P = Q[j][0];
		count = Q[j][1];
	}

	if( P != N )
		count = -1;
	printf( "%d\n", count );

	
	return 0;

}

0