結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-16 16:09:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,328 bytes |
| コンパイル時間 | 475 ms |
| コンパイル使用メモリ | 65,836 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-04 10:17:40 |
| 合計ジャッジ時間 | 1,377 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 20 |
ソースコード
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int func(int a) {
a = (a & 0x5555) + ((a >> 1) & 0x5555);
a = (a & 0x3333) + ((a >> 2) & 0x3333);
a = (a & 0x0F0F) + ((a >> 4) & 0x0F0F);
a = (a & 0x00FF) + ((a >> 8) & 0x00FF);
return a;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
cin >> n;
vector<int> vec(n + 1, 0); //既に来たかどうか
vec.at(1) = 1; //at(1)には既に来てる = 1 , 他はまだ行ってない = 0
queue<int> q;
q.push(1);
int count = 1; //移動数
while (!q.empty()) {
int position = q.front();
q.pop();
int step = func(position);
//戻るとき
if (position - step > 0 && vec.at(position - step) == 0) {
q.push(position - step);
vec.at(position - step) = 1;
count++;
}
//進むとき
if (position + step <= n && vec.at(position + step) == 0) {
q.push(position + step);
vec.at(position + step) = 1;
count++;
}
}
if (vec.at(n) == 0) {
cout << "-1" << endl;
} else {
cout << count << endl;
}
return 0;
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...
// 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1...