求优化代码, P1001 A+B ProblemTLE了
  • 板块灌水区
  • 楼主go_your_a_head
  • 当前回复9
  • 已保存回复10
  • 发布时间2024/11/23 15:25
  • 上次更新2024/11/23 17:29:13
查看原帖
求优化代码, P1001 A+B ProblemTLE了
1558515
go_your_a_head楼主2024/11/23 15:25
#include<bits/stdc++.h>
using namespace std;
int sub(int a,int b){
	if(!a)return b;
	return sub((a&b)<<1,a^b);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int a,b;
	cin>>a>>b;
	int l=-2e9,r=2e9;
	while(l+1!=r){
		long long mid=sub(l,r)>>1;
		if(sub(a,b)<=mid)r=mid;
		else l=mid;
	}
	cout<<r<<endl;
	return 0;
}

已经使用二分法优化了,但是还是TLE了,求改

https://www.luogu.com.cn/record/190578435

上面是测试记录

2024/11/23 15:25
加载中...