結果

問題 No.262 面白くないビットすごろく
ユーザー pekempeypekempey
提出日時 2015-10-07 17:23:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 1,200 ms
コンパイル使用メモリ 144,204 KB
実行使用メモリ 44,308 KB
最終ジャッジ日時 2023-09-27 07:45:38
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
44,264 KB
testcase_01 AC 109 ms
44,308 KB
testcase_02 AC 108 ms
44,292 KB
testcase_03 AC 107 ms
44,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

ll dp[40][1 << 16];
ll dp2[40][1 << 16];

int main() {
	ll N;
	cin >> N;
	ll mask = 0xffff;
	rep (i, 40) repr (j, 1 << 16) {
		ll next = j + __builtin_popcount(j) + i;
		if (next >= 1 << 16) {
			dp[i][j] = 1;
			dp2[i][j] = next & mask;
		} else {
			dp[i][j] = dp[i][next] + 1;
			dp2[i][j] = dp2[i][next];
		}
	}
	ll ans = 1;
	ll high = 0, low = 1;
	while ((high << 16) + low < N) {
		ll next_high = high + 1;
		ll next_low = dp2[__builtin_popcount(high)][low];
		if (N >= (next_high << 16) + next_low) {
			ans += dp[__builtin_popcount(high)][low];
			high = next_high;
			low = next_low;	
		} else {
			low += __builtin_popcount(low) + __builtin_popcount(high);
			high += low / (1 << 16);
			low &= mask;
			ans++;
		}
	}	
	if ((high << 16) + low > N) ans = -1;
	cout << ans << endl;
	return 0;
}
0