感觉思路没问题,毕竟过了三个点。后面的全都WA了。开了全局long long感觉也不可能爆,代码如下求大佬帮忙看看哪里出了问题。
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[5005],b[5005],c[5005];//a[i] is each stick,b[i] is the total of stick's length of i,c[i] is the total of two sticks combined at the length of i.
int ans;
const int mod = 1e9 + 7;
signed main(){
cin >> n;
for(int i = 1; i <= n;i ++){
cin >> a[i];
b[a[i]] ++;
}
for(int i = 1;i <= 2500;i ++){
for(int j = i + 1;j <= 5000 - i;j ++){
c[i + j] += b[i] * b[j];
}
}
for(int i = 1; i <= 2500;i ++){
if(b[i] > 1){
c[2 * i] += b[i] * (b[i] - 1) / 2;
}
}
for(int i = 1;i <= 5000;i ++){
if(b[i] > 1){
ans += b[i] * (b[i] - 1) / 2 * c[i] % mod;
}
}
cout << ans;
}