結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
めうめう🎒
|
| 提出日時 | 2016-01-22 18:59:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 170 ms / 5,000 ms |
| コード長 | 980 bytes |
| コンパイル時間 | 665 ms |
| コンパイル使用メモリ | 84,228 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:42:08 |
| 合計ジャッジ時間 | 3,763 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <sstream>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;
#define INF (1 << 30)
#define INFLL (1LL << 60)
int ido[10010] = {},n;
int bit_how(int n){
stringstream ss;
ss << bitset<32>(n);
int ans = 0;
for(int i = 0;i < ss.str().size();i++){
if(ss.str()[i] == '1') ans++;
}
return ans;
}
int memo[10010] = {};
int saiki(int now,int how){
if(memo[now] < how) return INF;
if(now > n) return INF;
if(now == n) return how;
int a,b;
memo[now] = how;
a = saiki(now + ido[now],how+1);
b = saiki(now - ido[now],how+1);
return min(a,b);
}
int main() {
int how;
for(int i = 0;i < 10010;i++) memo[i] = INF;
for(int i = 0;i < 10010;i++){
ido[i] = bit_how(i);
}
cin >> n;
int ans = saiki(1,1);
if(ans == INF) cout << "-1" << endl;
else cout << ans << endl;
return 0;
}
めうめう🎒