結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
kakeyamay
|
| 提出日時 | 2019-06-29 13:46:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 473 bytes |
| コンパイル時間 | 2,234 ms |
| コンパイル使用メモリ | 197,932 KB |
| 最終ジャッジ日時 | 2025-01-07 05:42:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
std::vector<int> memo(N,-1);
std::queue<int> q;
memo[0] = 1;
q.push(0);
while(!q.empty()){
int now = q.front();
q.pop();
int c = std::bitset<31>(now+1).count();
for(auto&next:{now+c,now-c}){
if(next<0||N<=next)continue;
if(memo[next]==-1){
memo[next] = memo[now]+1;
q.push(next);
}
}
}
int ans = memo[N-1];
ans = (ans==INT_MAX)?-1:ans;
std::cout << ans << std::endl;
}
kakeyamay