結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-15 07:37:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 399 bytes |
| コンパイル時間 | 754 ms |
| コンパイル使用メモリ | 74,644 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 08:46:36 |
| 合計ジャッジ時間 | 1,709 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main()
| ^~~~
ソースコード
#include<iostream>
#include<queue>
using namespace std;
int n;
queue<int>P;
int used[10001];
main()
{
cin>>n;
P.push(1);
used[1]=1;
while(!P.empty())
{
int u=P.front();P.pop();
int x=__builtin_popcount(u);
if(u-x>0&&!used[u-x])
{
used[u-x]=used[u]+1;
P.push(u-x);
}
if(u+x<=n&&!used[u+x])
{
used[u+x]=used[u]+1;
P.push(u+x);
}
}
cout<<(used[n]?used[n]:-1)<<endl;
}