結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 01:05:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 610 bytes |
| 記録 | |
| コンパイル時間 | 624 ms |
| コンパイル使用メモリ | 54,372 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-31 20:32:14 |
| 合計ジャッジ時間 | 1,638 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
#include <iostream>
#include <cstdio>
int N;
bool visited[10001];
int memo[10001];
int dfs(int pos){
if(pos < 1 || pos > N){return 1001001001;}
if(pos == N){return 1;}
if(visited[pos]){return 1001001001;}
if(memo[pos] != -1){return memo[pos];}
visited[pos] = true;
int bc = __builtin_popcount(pos);
return memo[pos] = std::min(dfs(pos-bc)+1, dfs(pos+bc)+1);
}
int main(){
std::cin >> N;
std::fill(memo, memo+10001, -1);
int res = dfs(1);
if(res < 1001001001){
printf("%d\n", res);
}else{
puts("-1");
}
}
tottoripaper