为什么这个代码只通过了 J 题 90% 的用例?

#include <iostream>
#include <vector>

using namespace std;
using LL = long long;

const LL MODULO = 998244353;

vector<LL> values, counts;

LL max_lose(LL n)
{
	LL result = 0;
	++n;
	while (n > 1)
	{
		n >>= 1;
		++result;
	}
	return result;
}

LL seg_lower(LL lose_max)
{
	return (1LL << lose_max) - 1;
}

LL seg_upper(LL lose_max)
{
	return (2LL << lose_max) - 1;
}

LL fast_pow(LL base, LL exponent)
{
	LL result = 1 % MODULO, multiplier = base % MODULO;
	while (exponent > 0)
	{
		if ((exponent & 1) == 1)
			result = result * multiplier % MODULO;
		multiplier = multiplier * multiplier % MODULO;
		exponent >>= 1;
	}
	return result;
}

int main()
{
	LL n = 0, m = 0;
	LL prob_mod = 0;
	cin >> n >> m;
	for (LL i = max_lose(n); seg_lower(i) < n + m; ++i)
	{
		values.push_back(i);
		if (n >= seg_lower(i) && n < seg_upper(i))
			counts.push_back(seg_upper(i) - n);
		else if (n + m >= seg_lower(i) && n + m < seg_upper(i))
			counts.push_back(n + m - seg_lower(i));
		else
			counts.push_back(seg_upper(i) - seg_lower(i));
	}
	prob_mod = 1;
	for (LL i = 0; i < values.size(); ++i)
	{
		LL den = 0, numer = 0;
		den = fast_pow((fast_pow(2, values[i]) - 1 + MODULO) % MODULO, counts[i]);
		numer = fast_pow(2, values[i] * counts[i]);
		prob_mod = prob_mod * den % MODULO * fast_pow(numer, MODULO - 2) % MODULO;
	}
	cout << prob_mod << '\n';
	return 0;
}

为什么这个代码只通过了 J 题 90\% 的用例?

全部评论
懒得理解你代码了,提供一组hack数据 8 1 答案应该是(1-1/2^3)=7/8=124780545 您的输出:606237885
4 回复 分享
发布于 2023-07-18 08:39 湖南

相关推荐

循此苦旅:月初笔试全a,没面试!
点赞 评论 收藏
分享
11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务