結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-08-29 13:43:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 727 bytes |
コンパイル時間 | 1,627 ms |
コンパイル使用メモリ | 167,032 KB |
実行使用メモリ | 14,016 KB |
最終ジャッジ日時 | 2024-09-13 14:14:50 |
合計ジャッジ時間 | 8,346 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define INF 101010101 int N, temp2[11000]; int huga(int a){ int ans=0; while(a){ if(a%2)ans++; a/=2; } return ans; } int foo(int a, int k){//cout<<a<<endl; if(a==N)return k; int temp = huga(a), ans=INF; if(a-temp >= 1){ if(temp2[a-temp]==0){ temp2[a-temp] = 1; ans = min(foo(a-temp,k+1), ans); temp2[a-temp] = 0; } } if(a+temp <= N){ if(temp2[a+temp]==0){ temp2[a+temp] = 1; ans = min(foo(a+temp,k+1), ans); temp2[a+temp] = 0; } } return ans; } signed main(){ cin>>N; int ans = foo(1,1); temp2[1]=1; if(ans==INF)cout<<-1<<endl; else cout<<ans<<endl; return 0; }