結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-04-09 23:10:16 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                MLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,735 bytes | 
| コンパイル時間 | 180 ms | 
| コンパイル使用メモリ | 25,728 KB | 
| 実行使用メモリ | 812,672 KB | 
| 最終ジャッジ日時 | 2024-07-18 01:39:47 | 
| 合計ジャッジ時間 | 1,917 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 MLE * 1 -- * 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 sugoroku( int P, int N, int c, int map[], int count )
{
	int map1[10000];
	int map2[10000];
	c++;
	if( P == N )
	{
		if( count == 0 || c < count )
			count = c;
		return( count );
	}
	if( map[P] == 0 )
		map[P] = 1;
	else
	{
		return( count );
	}
	memcpy( map1, map, sizeof(int)*1000 );
	memcpy( map2, map, sizeof(int)*1000 );
	int ido = bit( P );
	//printf( "P:%d bit:%d\n", P,  ido );
	//右に移動できるか確認
	if( P + ido <= N )
	{
		count = sugoroku( P + ido, N, c, map1, count );
	}
	//左に移動できるか確認
	if( P - ido > 0 )
	{
		count = sugoroku( P - ido, N, c, map2, count );
	}
	return count;
}
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 map[10000] = {0};
	
	
	int count = sugoroku( 1, N, 0, map, 0 );
	
	if( count == 0 )
		count = -1;
	printf( "%d\n", count );
	
	return 0;
}
            
            
            
        