結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-07-15 07:34:00 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 430 bytes | 
| コンパイル時間 | 693 ms | 
| コンパイル使用メモリ | 63,924 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-08 01:33:00 | 
| 合計ジャッジ時間 | 1,749 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 WA * 19 | 
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main()
      | ^~~~
            
            ソースコード
#include<iostream>
using namespace std;
int n;
bool used[10001];
int bfs(int i)
{
	used[i]=1;
	if(i==n)return 1;
	int x=__builtin_popcount(i);
	int ans1=-1,ans2=-1;
	if(i-x>0&&!used[i-x])ans1=bfs(i-x);
	if(i+x<=n&&!used[i+x])ans2=bfs(i+x);
	if(ans1==-1&&ans2==-1)return -1;
	else
	{
		if(ans1==-1)return ans2+1;
		else if(ans2==-1)return ans1+1;
		else return (ans1<ans2?ans1:ans2)+1;
	}
}
main()
{
	cin>>n;
	cout<<bfs(1)<<endl;
}
            
            
            
        