/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 7ms 1.465 MiB
#3 Accepted 7ms 1.465 MiB
#4 Accepted 26ms 804.0 KiB
#5 Accepted 34ms 784.0 KiB
#6 Accepted 35ms 592.0 KiB
#7 Accepted 39ms 588.0 KiB
#8 Accepted 62ms 596.0 KiB
#9 Accepted 39ms 588.0 KiB

Code

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

typedef long long ll;
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define mp make_pair
#define pq priority_queue<int>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define PI acos(-1)
const int M = 1e9 + 7;
ll binExp(ll a, ll b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = res * a;
        a *= a;
        b /= 2;
    }
    return res;
}
ll gcd(ll a, ll b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}
void solve() {
    ll n;
    cin >> n;
    string s;
    map<char, ll> m;
    ll ans = 0, f = 0;
    cin >> s;
    f(i, n) {
        m[s[i]]++;
    }
    for (auto [a, b] : m) {
        if (b > 1) {
            f = 1;
            ans += b * (b - 1);
        }
    }
    if (f)
        cout << ans << '\n';
    else
        cout << "0\n";
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 15:31:37
Judged At
2024-10-03 13:51:51
Judged By
Score
100
Total Time
62ms
Peak Memory
1.465 MiB