(玄关)求本地结果与评测机不一致原因
  • 板块学术版
  • 楼主Zcras
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/21 21:15
  • 上次更新2024/11/21 23:14:47
查看原帖
(玄关)求本地结果与评测机不一致原因
573977
Zcras楼主2024/11/21 21:15

rt,在P10484wa了很多发之后,从acwing偷了一组错误数据

2147483647 26
12
26
52
104
208
396
5541
8869
11215
30903
117017
25932253
2144190
889685
771709443
1414390643
2013009336
67577432
175529294
886309091
44872
1992993994
760776077
829253885
11757443
292908201

标准答案2144708006与本地输出一致,但acwing显示我的输出是2146852196,求原因及注意事项总结

#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int,int> PII;
const int N=50,INF=0x3f3f3f3f,MOD=1e9+7;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
void write(int x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar(x+'0');
		return;
	}
	write(x/10);
	putchar(x%10+'0');
	return;
}
int n,m,ans=0,minn=INF,maxn=-INF;
int g[N];
vector<int>t1,t2;
void dfs1(int u,int s){
	if(u==n/2+1){
		if(s<=m){
			t1.push_back(s);	
		}
		return;
	}
	dfs1(u+1,s+g[u]);
	dfs1(u+1,s);
	return;
}
void dfs2(int u,int s){
	if(u==n+1){
		if(s<=m){
			t2.push_back(s);	
		}
		return;
	}
	dfs2(u+1,s+g[u]);
	dfs2(u+1,s);
	return;
}
signed main(){
	m=read(),n=read();
	for(int i=1;i<=n;i++){
		g[i]=read();
	}
	dfs1(1,0);
	dfs2(n/2+1,0);
	sort(t1.begin(),t1.end());
	sort(t2.begin(),t2.end());
	for(int i=0;i<t1.size();i++){
		int l=0,r=t2.size()-1,mid=0;
		while(l<r){
			mid=(l+r+1)/2;
			if(t2[mid]+t1[i]>m){
				r=mid-1;
			}else{
				l=mid;
			}
		}
		if(t2[mid]+t1[i]<=m){
			ans=max(ans,t2[mid]+t1[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
2024/11/21 21:15
加载中...