結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2017-10-16 22:06:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,446 bytes |
コンパイル時間 | 1,655 ms |
コンパイル使用メモリ | 173,000 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-01 08:49:49 |
合計ジャッジ時間 | 2,618 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define times(n, i) uptil(0, n, i) #define rtimes(n, i) downto((n) - 1, 0, i) #define upto(f, t, i) for(int i##_to_ = (t), i = (f); i <= i##_to_; i++) #define uptil(f, t, i) for(int i##_to_ = (t), i = (f); i < i##_to_; i++) #define downto(f, t, i) for(int i##_to_ = (t), i = (f); i >= i##_to_; i--) #define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i > i##_to_; i--) typedef long double LD; #define long long long #if defined(EBUG) && !defined(ONLINE_JUDGE) #define debug true #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 2 #define _LIBCPP_DEBUG2 2 #define ln << endl #else #define debug false #define ln << '\n' #endif #define tb << '\t' #define sp << ' ' inline int bc(long x) { int a = 0; while(x) { a += x & 1; x >>= 1; } return a; } signed main() { // long: 64bit if(!debug) { cin.tie(0); ios::sync_with_stdio(0); } int N; scanf("%d", &N); vector<int> pyon(N+1, -1); pyon[1] = 1; queue<int> q; q.push(1); while(!q.empty()) { int i = q.front(); q.pop(); int b = bc(i); if(debug) cout << i sp << b ln; for(int j : {i+b, i-b}) { if(1 <= j && j <= N && pyon[j] == -1) { pyon[j] = pyon[i] + 1; q.push(j); if(debug) cout << j ln; } } } cout << pyon[N] ln; return 0; }