結果

問題 No.3 ビットすごろく
ユーザー 184184
提出日時 2014-10-01 00:17:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 67,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 19:58:52
合計ジャッジ時間 2,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>

using namespace std;


int bitcount(int a){
	int cnt=0;
	do{if(a&1)cnt++;}
	while(a>>=1);
	return cnt;
}
int main(){
	int move[20000];
	
	int n;
	scanf("%d", &n);
	for(int i = 1; i<=n; i++){
		move[i] = bitcount(i);
	}
	int pos[20000];
	for(int i=0;i<=n;i++)pos[i]=-1;
	pos[1] = 1;
	
	int cnt = 1;
	int l = 1;
	while(cnt <= n){
		cnt++;
		int ll = l;
		for(int i=1; i<=l; i++){
			//printf("%d ",pos[i]);
			if(pos[i] == cnt-1){
				//pos[i] = -1;
				if(i + move[i] == n){
					printf("%d\n", cnt);
					return 0;
				}
				else if(i + move[i] < n){
					if(ll<i+move[i])l=i+move[i];
					if(pos[i+move[i]]==-1||cnt<pos[i+move[i]])pos[i + move[i]] = cnt;
				}
				if(i - move[i] > 0){
					if(pos[i-move[i]]==-1||cnt<pos[i-move[i]])pos[i - move[i]] = cnt;
				}
			}
		} 
	}
	if(pos[n] == -1)printf("-1\n");
	 for(int i=n;i>0;i--)if(pos[i]!=-1)printf("%d ",pos[i]);
	return 0;
}
0