結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
09SEPGR
|
| 提出日時 | 2017-10-21 22:25:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,151 bytes |
| コンパイル時間 | 975 ms |
| コンパイル使用メモリ | 85,432 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 12:39:19 |
| 合計ジャッジ時間 | 2,126 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 1 |
ソースコード
/*
* main.cpp
*
* Created on: 2017/10/06
* Author: sep
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
inline int main003();
inline int main2();
inline int main3();
inline int main4();
int main() {
main003();
return 0;
}
inline int get_bit(int x) {
int c = 0;
while (x) {
if (x & 1)
c++;
x >>= 1;
}
return c;
}
inline int main003() {
int num;
int route, v1, v2, bit_count;
int result = 0;
map<int, int> v;
queue<int> q;
cin >> num;
q.push(1);
v[1] = 1;
while (!q.empty()) {
route = q.front();
q.pop();
bit_count = get_bit(route);
v1 = route + bit_count;
v2 = route - bit_count;
if (v1 == num) {
result = v[route] + 1;
break;
}
if ((v1 < num) && (v[v1] == 0 || v[route] + 1 < v[v1])) {
v[v1] = v[route] + 1;
q.push(v1);
}
if ((0 < v2) && (v[v2] == 0 || v[route] + 1 < v[v2])) {
v[v2] = v[route] + 1;
q.push(v2);
}
}
if (result == 0) {
cout << -1;
} else {
cout << result;
}
return 0;
}
09SEPGR