結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
spade630
|
| 提出日時 | 2015-10-19 12:11:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 698 bytes |
| コンパイル時間 | 684 ms |
| コンパイル使用メモリ | 64,860 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-21 19:46:56 |
| 合計ジャッジ時間 | 1,932 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
ソースコード
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int INF = 1e+9;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int ans = -1;
queue<int> que;
que.push(1);
bool visited[10001] = {0};
int d[10001] = {0};
d[1] = 1;
while(!que.empty()){
int p = que.front(); que.pop();
if(n == p){
ans = d[p];
break;
}
if(visited[p]){
continue;
}
visited[p] = true;
int next = __builtin_popcount(p);
if(next + p <= n){
d[next + p] = d[p] + 1;
que.push(next + p);
}
if(p - next >= 1){
d[p - next] = d[p] + 1;
que.push(p - next);
}
}
cout << ans << endl;
return 0;
}
spade630