結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2021-01-04 11:35:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,435 bytes |
コンパイル時間 | 781 ms |
コンパイル使用メモリ | 91,864 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 14:08:36 |
合計ジャッジ時間 | 1,592 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#include <iostream> // cout, endl, cin #include <cmath> //sqrt pow #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // dequef #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <climits> #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using ld = long double; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define mod 1000000007 using namespace std; int cnt(int n){ int res = 0; while(n){ res += (n & 1); n >>= 1; } return res; } int main(){ int n; cin >> n; int pos = 1, ans = 1; while(pos != n){ int num = cnt(pos); if(pos + num > n && pos - num < 1){ cout << -1 << endl; return 0; } if(pos + num > n) pos -= num; else pos += num; ans++; if(ans > n){ cout << -1 << endl; return 0; } } cout << ans << endl; }