結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-20 18:40:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 669 bytes |
| コンパイル時間 | 1,074 ms |
| コンパイル使用メモリ | 157,788 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-26 09:25:56 |
| 合計ジャッジ時間 | 2,066 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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){
if(a%2)ans++;
a/=2;
}
//cout<<ans<<endl;
return ans;
}
int foo(int a, int k){//cout<<a<<endl;
if(a==N)return k+1;
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,0);
if(ans==INF)cout<<-1<<endl;
else cout<<ans<<endl;
return 0;
}