結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
ふう
|
| 提出日時 | 2015-02-07 12:26:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,102 bytes |
| コンパイル時間 | 937 ms |
| コンパイル使用メモリ | 87,424 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 10:37:49 |
| 合計ジャッジ時間 | 2,091 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 1 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define SIZE 10000
using namespace std;
/* 1のビット数 */
int numofbits(long bits)
{
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
int main()
{
int d[SIZE];
int N;
queue<int> que;
cin >> N;
memset(d, -1, sizeof(d));
que.push(1);
d[1] = 1;
while (que.size()) {
int p = que.front();
que.pop();
int n = p + numofbits(p);
if (0 < n && n <= N && d[n] == -1) {
que.push(n);
d[n] = d[p] + 1;
}
n = p - numofbits(p);
if (0 < n && n <= N && d[n] == -1) {
que.push(n);
d[n] = d[p] + 1;
}
}
cout << d[N] << endl;
}
ふう