求助,造的数据全对,测试点全wa,邪了门了
查看原帖
求助,造的数据全对,测试点全wa,邪了门了
713664
zxcpyy楼主2023/11/24 20:47

自己造数据全过,测试点全挖

#include<bits/stdc++.h>
using namespace std;
const int N = 5010;
const int INF = 0x3f3f3f3f;
typedef pair<int,int> PII;
typedef long long LL;
const int mod = 1e9 + 7;

#define endl '\n'
#define x first
#define y second
int f[N];
int q[N];
int qim(int b, int a)
{
   int res = 1;
   while(a)
   {
       if(a & 1) res = (LL) res * b  % mod ;
       b = (LL) b *  b  % mod;
       a >>= 1;
   }
   return res;
}
void solve(){
  int n;
  LL ans = 0;

  cin >> n;
  unordered_map<int,int> m;
  vector<int> a(n);
  for(int i = 0; i < n; i ++){
    int x;
    cin >> x;
    m[x] ++;
    a.push_back(x);

  }
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  for(int i = 0; i < a.size(); i ++){
    for(int j = i ; j < a.size(); j ++){
       int l = a[i] , r = a[j];
       int l1 = m[l] , r1 = m[r];
      if(i == j && m[l + l] >= 2 && m[l] >= 2){
       
         ans = (ans +  (LL)f[l1] * q[l1 - 2] % mod * q[2] % mod * (LL)f[m[2 * l]] * q[m[2 * l] - 2] % mod * q[2] % mod)%mod;
         
      }
      else if(m[l] >= 1 && m[r] >= 1 && m[l + r] >= 2)
      {
          ans = (ans +  (LL)l1 * r1 * (LL)f[m[l + r]] % mod * q[m[l + r] - 2] * q[2] % mod )%mod;
      
    }
  }
}
  cout << ans % mod  << endl;
  
}
int main()
{

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  f[0]  = q[0] = 1;
   for(int i = 1; i < N; i ++)
   {
       f[i] = (LL)f[i - 1] * i % mod;
       q[i] = (LL)q[i - 1] * qim(i , mod - 2 ) %  mod;
       
   }
  int t = 1;
  //cin >> t;
  while(t --) solve();
  return 0;
}
2023/11/24 20:47
加载中...