結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
|
| 提出日時 | 2023-06-10 16:23:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 746 bytes |
| コンパイル時間 | 555 ms |
| コンパイル使用メモリ | 62,332 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-02 21:55:08 |
| 合計ジャッジ時間 | 1,903 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 RE * 2 |
ソースコード
#include<stdio.h>
#include<iostream>
using namespace std;
int bit(int x)
{
int i = 1;
while (x > 1)
{
if (x % 2 == 0)
{
x = x / 2;
}
else
{
x = (x - 1) / 2;
i++;
}
}
return i;
}
int main()
{
int N, i,j, a[10000] = {};
cin >> N;
j = 0;
a[1] = 1;
for (j = 1; j <= 5; j++)
{
i = 1;
while (i <= N)
{
if (a[i] == 0)
{
i++;
continue;
}
if ((a[i + bit(i)] == 0) || (a[i + bit(i)] > a[i]))
{
a[i + bit(i)] = a[i] + 1;
}
if ((i > bit(i)) && ((a[i - bit(i)] > a[i])||(a[i-bit(i)]==0)))
{
a[i - bit(i)] = a[i] + 1;
}
i++;
}
}
if(a[N]==0)
{
cout << "-1";
}
else
{
cout << a[N];
}
return 0;
}