結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-04-10 00:47:19 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,435 bytes | 
| コンパイル時間 | 225 ms | 
| コンパイル使用メモリ | 25,600 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-18 01:40:23 | 
| 合計ジャッジ時間 | 4,904 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 RE * 29 | 
ソースコード
#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;
	
	for( ; P < N;  j++ )
	{
		if( P+ bit( P ) <= N )
		{
			i++;
			Q[i][0] = P+ bit( P );
			Q[i][1] = count+1;
		}
		if( P - bit(P) > 0 )
		{
			i++;
			Q[i][0] = P - bit( P );
			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;
}
            
            
            
        