結果

問題 No.3 ビットすごろく
ユーザー prog470
提出日時 2015-05-31 18:49:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 61,624 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-07-06 13:05:06
合計ジャッジ時間 6,964 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 3 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0