/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 15ms 16.02 MiB
#2 Wrong Answer 21ms 16.922 MiB
#3 Wrong Answer 20ms 16.707 MiB

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define bug(a) cout << #a << " : " << a << endl;

const ll N = 1e6, mod = 1e9 + 7;

ll power(long long n, long long k) {
    ll ans = 1 % mod; n %= mod; if (n < 0) n += mod;
    while (k) {
        if (k & 1) ans = (long long) ans * n % mod;
        n = (long long) n * n % mod;
        k >>= 1;
    }
    return ans;
}
ll f[N], invf[N];
ll nCr(ll n, ll r) {
    if (n < r or n < 0) return 0;
    return 1LL * f[n] * invf[r] % mod * invf[n - r] % mod;
}

ll nPr(ll n, ll r) {
    if (n < r or n < 0) return 0;
    return 1LL * f[n] * invf[n - r] % mod;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    f[0] = 1;
    for (ll i = 1; i < N; i++) {
        f[i] = 1LL * i * f[i - 1] % mod;
    }
    invf[N - 1] = power(f[N - 1], mod - 2);
    for (ll i = N - 2; i >= 0; i--) {
        invf[i] = 1LL * invf[i + 1] * (i + 1) % mod;
    }
    ll t = 1; cin >> t;
    while (t--) {
        ll n; cin >> n;
        string s;cin>>s;
        map<char,ll>mp;
        for(auto i:s)mp[i]++;
        ll ans=0;
        for(auto i:mp){
            ans+=nCr(i.second,2);
        }
        cout<<ans*2<<endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-07 20:09:04
Judged At
2024-12-07 20:09:04
Judged By
Score
10
Total Time
21ms
Peak Memory
16.922 MiB