結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-02 02:53:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 556 bytes |
| コンパイル時間 | 1,287 ms |
| コンパイル使用メモリ | 163,060 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:18:16 |
| 合計ジャッジ時間 | 2,266 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
int dp[10000 + 1];
int main() {
int N;
cin >> N;
fill(dp, dp + 10001, -1);
dp[1] = 1;
queue<int> q;
q.push(1);
while (!q.empty()) {
int x = q.front(); q.pop();
int d = __builtin_popcount(x);
if (x - d > 0) {
if (dp[x - d] == -1) {
dp[x - d] = dp[x] + 1;
q.push(x - d);
}
}
if (x + d <= N) {
if (dp[x + d] == -1) {
dp[x + d] = dp[x] + 1;
q.push(x + d);
}
}
}
cout << dp[N] << endl;
}