結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-31 18:39:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 636 bytes |
| コンパイル時間 | 442 ms |
| コンパイル使用メモリ | 60,936 KB |
| 実行使用メモリ | 10,144 KB |
| 最終ジャッジ日時 | 2024-07-06 13:04:47 |
| 合計ジャッジ時間 | 7,129 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 3 TLE * 1 -- * 21 |
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int henkan(int num){
int c=0;
while(num>0){
if(num%2==1){
c++;
}
num = num/2;
}
return c++;
}
int solv(int N){
int walk;
vector<int> flag(N+1,0);
int pos = 1, count = 1;
while(true){
flag[pos] = 1;
walk = henkan(pos);
if(pos+walk == N){
return count+1;
}else if(pos+walk < N){
if(flag[pos+walk]==0){
pos = pos+walk;
count++;
}
}else{
if(flag[pos-walk] == 0){
pos = pos-walk;
count++;
}else{
return -1;
}
}
}
}
int main(){
int N;
cin>>N;
cout<<solv(N)<<endl;
return 0;
}