結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
Projectormato
|
| 提出日時 | 2018-02-02 01:19:23 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 825 bytes |
| 記録 | |
| コンパイル時間 | 1,301 ms |
| コンパイル使用メモリ | 185,936 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2026-03-22 05:47:28 |
| 合計ジャッジ時間 | 2,499 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:16: 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]
35 | puts(dist[n])
| ^
main.cpp:8:17: note: in definition of macro 'puts'
8 | #define puts(x) x; cout << x << endl;
| ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:68,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/queue:69,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:160,
from main.cpp:1:
/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<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long
int main(){
int n, INF = 100000000;
cin >> n;
queue<int> q;
q.push(1);
vector<int> dist(n+1, INF);
dist[1] = 1;
while (!q.empty()) {
int now = q.front();
q.pop();
int bit = bitset<32>(now).count();
if (now-bit > 0 && dist[now-bit] == INF) {
dist[now-bit] = dist[now]+1;
q.emplace(now-bit);
}
if (now+bit <= n && dist[now+bit] == INF) {
dist[now+bit] = dist[now]+1;
q.emplace(now+bit);
}
}
if (dist[n] == INF) {
puts(-1)
}else{
puts(dist[n])
}
}
Projectormato