結果

問題 No.262 面白くないビットすごろく
コンテスト
ユーザー shobonvip
提出日時 2026-08-06 03:56:57
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 110µs
コード長 2,194 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,286 ms
コンパイル使用メモリ 375,116 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-06 03:57:03
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
	author:  shobonvip
	created: 2026.08.06 03:40:39
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

pair<ll,ll> dp[70][140][70];
bool seen[70][140][70];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	auto f = [&](auto F, ll a, ll b, ll c) -> pair<ll,ll> {
		if (seen[a][b][c]) return dp[a][b][c];
		if (b >= (1LL<<c)) return pair(0, b);

		ll cnt = 0;
		ll toc = 0;

		if (c == 0LL) {
			//cout << a << ' ' << b << ' ' << c << endl;
			assert(b == 0LL);
			return pair(1, a);
		}

		if (c >= 1 && b >= (1LL<<(c-1))) {
			auto [cnt_v, toc_v] = F(F, a+1, b-(1LL<<(c-1)), c-1);
			cnt = cnt_v;
			toc = toc_v + (1LL<<(c-1));
		} else {
			auto [cnt_v, toc_v] = F(F, a, b, c-1);
			auto [cnt_w, toc_w] = F(F, a+1, toc_v - (1LL<<(c-1)), c-1);
			cnt = cnt_v + cnt_w;
			toc = toc_w + (1LL<<(c-1));
		}

		dp[a][b][c] = pair(cnt, toc);
		seen[a][b][c] = 1;
		return dp[a][b][c];
	};

	ll a = 0;
	ll b = 1;
	ll ans = 0;
	rrep(c, 0, 60) {
		if (n >> c & 1) {
			auto [cnt, toc] = f(f, a, b, c);
			b = toc - (1LL << c);
			ans += cnt;
			a++;
		}
	} 

	if (b == 0) {
		cout << ans + 1 << endl;
	} else {
		cout << -1 << endl;
	}

}

0