結果

問題 No.3 ビットすごろく
ユーザー prog470prog470
提出日時 2015-05-31 18:49:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 62,396 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 18:09:41
合計ジャッジ時間 8,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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