結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-08-20 18:47:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 692 bytes |
コンパイル時間 | 1,118 ms |
コンパイル使用メモリ | 157,804 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-26 10:12:56 |
合計ジャッジ時間 | 2,006 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 19 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define INF 101010101 int N, temp2[11000]; int huga(int a){//cout<<a<<endl; int ans=0; while(a){//cout<<a%2; if(a%2)ans++; a/=2; }//cout<<endl; //cout<<ans<<endl; return ans; } int foo(int a, int k){//cout<<a<<endl; if(a==N)return k; temp2[a]=1; int temp = huga(a), ans=INF; if(a-temp >= 1){ if(temp2[a-temp]==0){ ans = min(foo(a-temp,k+1), ans); } } if(a+temp <= N){ if(temp2[a+temp]==0){ ans = min(foo(a+temp,k+1), ans); } } return ans; } signed main(){ cin>>N; int ans = foo(1,1); if(ans==INF)cout<<-1<<endl; else cout<<ans<<endl; return 0; }