結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-17 19:03:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,307 bytes |
| コンパイル時間 | 764 ms |
| コンパイル使用メモリ | 88,452 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-22 08:36:58 |
| 合計ジャッジ時間 | 1,795 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 1 |
ソースコード
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>
ll ans[11000], n;
queue<P> q;
int main() {
REP(i, 11000)ans[i] = INF;
cin >> n;
ans[1] = 0;
q.push(P(1, 1));
while (!q.empty()) {
P now = q.front();
q.pop();
ll cnt = 0, nowf = now.first;
while (nowf > 0) {
if (nowf % 2 == 1)cnt++;
nowf /= 2;
}
if (now.first - cnt > 0) {
if (ans[now.first - cnt] > now.second + 1) {
q.push(P(now.first - cnt, now.second + 1));
ans[now.first - cnt] = now.second + 1;
}
}
if (now.first + cnt <= n) {
if (ans[now.first + cnt] > now.second + 1) {
q.push(P(now.first + cnt, now.second + 1));
ans[now.first + cnt] = now.second + 1;
}
}
}
if (ans[n] == INF)cout << -1 << endl;
else cout << ans[n] << endl;
}