結果

問題 No.262 面白くないビットすごろく
ユーザー FF256grhy
提出日時 2015-08-01 02:42:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 606 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 173,600 KB
最終ジャッジ日時 2024-07-18 00:21:03
合計ジャッジ時間 3,546 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%lld", &n);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int bc(int a) {
	int c = 0;
	while(a) {
		c += a % 2;
		a /= 2;
	}
	return c;
}

int time[21][1 << 20];
int next[21][1 << 20];

int main(void) {
	long long int n;
	scanf("%lld", &n);
	
	int u = n >> 20, l = n % (1 << 20), i, j;
	
	for(i = 0; i <= 20; i++) {
	for(j = (1 << 20) - 1; 0 <= j; j--) {
		int k = j + i + bc(j);
		if( (1 << 20) <= k ) {
			time[i][j] = 1;
			next[i][j] = k % (1 << 20);
		} else {
			time[i][j] = time[i][k] + 1;
			next[i][j] = next[i][k];
		}
	}
	}
	
	int up, lp = 1;
	long long int c = 1;
	for(up = 0; up < u; up++) {
		c += time[ bc(up) ][lp];
		lp = next[ bc(up) ][lp];
	}
	
	while(lp < l) {
		lp += bc(u) + bc(lp);
		c++;
	}
	
	printf("%lld\n", (lp == l) ? c : -1 );
	return 0;
}
0