結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-02-09 13:28:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 834 bytes |
コンパイル時間 | 766 ms |
コンパイル使用メモリ | 73,596 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-25 17:19:13 |
合計ジャッジ時間 | 1,733 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#include <iostream> #include <queue> using namespace std; const int INF = 100000000; int main(void){ int n, i; int v[10005], d[10005]; cin >> n; for(int i=1;i<=n;i++){ v[i] = 0; } for(int i=1;i<=n;i++){ d[i] = INF; } i=1; queue<int> que; que.push(1); v[1] = 1; d[1] = 1; while(!que.empty()){ int bit; i = que.front(); que.pop(); bit = __builtin_popcount(i); if(i+bit >= 1 && i+bit <= n && v[i+bit] == 0){ que.push(i+bit); v[i+bit] = 1; d[i+bit] = d[i] + 1; } if(i-bit >= 1 && i-bit <= n && v[i+bit] == 0){ que.push(i-bit); v[i-bit] = 1; d[i-bit] = d[i] + 1; } } cout << (d[n] != INF ? d[n] : -1) << endl; return 0; }