/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 6ms 1.465 MiB
#3 Accepted 6ms 1.664 MiB
#4 Accepted 23ms 792.0 KiB
#5 Accepted 31ms 780.0 KiB
#6 Accepted 31ms 600.0 KiB
#7 Accepted 36ms 604.0 KiB
#8 Accepted 56ms 596.0 KiB
#9 Accepted 35ms 580.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-10-03 13:52:45
Judged By
Score
100
Total Time
56ms
Peak Memory
1.664 MiB