社区讨论

样例全过,但WA声一片

灌水区参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@m38hq83i
此快照首次捕获于
2024/11/08 16:44
去年
此快照最后确认于
2025/11/04 15:08
4 个月前
查看原帖

求助 P4995 跳跳!

CPP
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans,a[305],z;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	int x=n,y=1;
	while(x>y){
		ans+=(a[x]-z)*(a[x]-z);
		ans+=(z-a[y])*(z-a[y]);
		z=a[y],x--,y++;
	}
	if(x==y)ans+=(a[x]-z)*(a[x]-z);
	cout<<ans;
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...