結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
tamaron
|
| 提出日時 | 2019-12-18 14:09:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 874 bytes |
| コンパイル時間 | 1,152 ms |
| コンパイル使用メモリ | 164,460 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 09:56:11 |
| 合計ジャッジ時間 | 2,205 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const long long INF = 1e18;
vector<ll> dp(10100,0);
vector<bool> visited(10100,false);
queue<ll> que;
ll stands(ll num){
ll cnt=0;
while(num>0){
if(num%2==1) ++cnt;
num/=2;
}
return cnt;
}
int main() {
ll N;
cin>>N;
que.push(1);
dp[1]=1;
while(!que.empty()){
ll node=que.front();que.pop();
if(visited[node]) continue;
visited[node]=true;
ll st=stands(node);
if (0<node-st && node-st<=N){
dp[node-st]=dp[node]+1;
que.push(node-st);
}
if (0<node+st && node+st<=N){
dp[node+st]=dp[node]+1;
que.push(node+st);
}
}
if (dp[N]==0) cout<<-1<<endl;
else cout<<dp[N]<<endl;
return 0;
}
tamaron