1 条题解

  • 0
    @ 2024-10-25 22:20:12

    Answer is here!

    #include <bits/stdc++.h> 
    
    using namespace std;
    
    typedef long long ll;
    
    const int MAXN = 5e5 + 10;
    const int mod = 20051131;
    
    int n, cnt[MAXN]; ll ans = 1, sum;
    
    int main() {
        scanf("%d", &n);
        for (int i = 1, x; i <= n; i++) scanf("%d", &x), cnt[x]++;
        sort(cnt + 1, cnt + n + 1, greater<int>());
        for (int i = 1; i <= n; i++) {
            if (!cnt[i]) break;
            for (int j = 1; j < cnt[i]; j++) ans = ans * j % mod;
            if (i > 1) ans = ans * (sum - (ll)(i - 1) * cnt[i]) % mod; sum += cnt[i];
        }
        printf("%lld", ans);
    }
    

    Thank you very much!

    信息

    ID
    78
    时间
    3000ms
    内存
    512MiB
    难度
    6
    标签
    递交数
    126
    已通过
    76
    上传者