/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 436.0 KiB
#2 Accepted 6ms 1.5 MiB
#3 Accepted 6ms 1.637 MiB
#4 Accepted 24ms 824.0 KiB
#5 Accepted 31ms 796.0 KiB
#6 Accepted 33ms 608.0 KiB
#7 Accepted 36ms 608.0 KiB
#8 Accepted 57ms 584.0 KiB
#9 Accepted 35ms 584.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, m, a[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    cin >> tc;
    while (tc--) {
        map<char, int> mp;
        string s;
        cin >> n >> s;
        for (auto i : s) {
            mp[i]++;
        }
        ll Ans = 0;
        for (auto i : mp) {
            ll cnt = i.S;
            Ans += (cnt * (cnt - 1));
        }
        cout << Ans << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 15:10:47
Judged At
2024-11-11 03:35:01
Judged By
Score
100
Total Time
57ms
Peak Memory
1.637 MiB