結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mine691
|
| 提出日時 | 2018-07-06 14:27:54 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 758 bytes |
| 記録 | |
| コンパイル時間 | 489 ms |
| コンパイル使用メモリ | 96,240 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-03-21 19:34:49 |
| 合計ジャッジ時間 | 1,416 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 23 |
コンパイルメッセージ
main.cpp: In function 'int bfs(int)':
main.cpp:14:11: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
14 | root[1];
| ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:68,
from main.cpp:2:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:1261:7: note: declared here
1261 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ^~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int INF = 1e9;
int bfs(int n)
{
queue<int> q;
q.push(1);
vector<int> root(n + 1, INF);
root[1];
while (q.size())
{
int now = q.front();
q.pop();
int next = __builtin_popcount(now);
if (now - next > 0 && root[next] == INF)
{
root[next] = now + 1;
q.emplace(now - next);
}
if (now + next <= n && root[next] == INF)
{
root[next] == now + 1;
q.emplace(now + next);
}
}
if (root[n] == INF)
return -1;
else
return root[n];
}
int main()
{
int n;
cin >> n;
cout << bfs(n) << endl;
}
mine691