結果

問題 No.262 面白くないビットすごろく
ユーザー piyoko_212piyoko_212
提出日時 2015-12-28 20:55:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 39,080 KB
実行使用メモリ 7,076 KB
最終ジャッジ日時 2023-08-25 02:37:41
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
7,064 KB
testcase_01 AC 278 ms
7,064 KB
testcase_02 AC 282 ms
7,076 KB
testcase_03 AC 279 ms
6,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
using namespace std;
int pc[1<<20];
int to[21][40];
int cost[21][40];
int main(){
	long long a;scanf("%lld",&a);
	for(int i=0;i<(1<<20);i++){
		pc[i]=__builtin_popcount(i);
	}
	for(int i=0;i<21;i++){
		for(int j=0;j<40;j++){
			if(i==0&&j!=1)continue;
			int now=j;
			int cnt=0;
			while(now<(1<<20)){
				now+=pc[now]+i;
				cnt++;
			}
			to[i][j]=now-(1<<20);
			cost[i][j]=cnt;
		}
	}
	long long ret=0;
	long long at=1;
	for(int i=0;i<(a>>20);i++){
		int p=pc[i];
		ret+=cost[p][at];
		at=to[p][at];
	}
	at+=((a>>20)<<20);
	while(at<a){
		ret++;
		at+=pc[at%(1<<20)]+pc[at>>20];
	}
	if(a==at){
		printf("%lld\n",ret+1);
	}else printf("-1\n");
}
0