P3799 妖梦拼木棒

// Problem: P3799 妖梦拼木棒
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3799
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> info(5010);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        ++info[t];
    }
    
    long long res = 0;
    for (int i = 1; i < info.size(); ++i) {
        for (int j = i; i + j < info.size(); ++j) {
            int longer = i + j;
            if (i == j) {
                res += info[longer] * (info[longer] - 1LL) / 2 * info[i] * (info[i] - 1) / 2;
            } else {
                res += info[longer] * (info[longer] - 1LL) / 2 * info[i] * info[j];
            }
            res %= 1000000007;
        }
    }
    cout << res << endl;
    return 0;
}
posted @ 2022-02-09 16:46  Pannnn  阅读(31)  评论(0)    收藏  举报
-->