結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2014-11-16 14:41:14 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,057 bytes |
| 記録 | |
| コンパイル時間 | 609 ms |
| コンパイル使用メモリ | 96,284 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2026-03-22 02:55:00 |
| 合計ジャッジ時間 | 1,455 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int main(){
queue<pair<int,int>> q;
int n,now,mo,bit,k;
bool sude[10001]={};
scanf("%d",&n);
q.push(make_pair(1,1));
sude[1]=true;
for(;!q.empty();){
now = bit =q.front().first;
k = q.front().second;
q.pop();
if(now==n){
printf("%d\n",k);
return 0;
}
mo=0;
while(bit>0){
mo+=bit%2;
bit/=2;
}
if(mo<now)
if(!sude[now-mo]){
q.push(make_pair(now-mo,k+1));
sude[now-mo]=true;
}
if(mo+now<=n)
if(!sude[now+mo]){
q.push(make_pair(now+mo,k+1));
sude[now+mo]=true;
}
}
printf("-1\n");
return 0;
}
goodbaton