/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 7ms 1.508 MiB
#3 Accepted 6ms 1.547 MiB
#4 Accepted 26ms 796.0 KiB
#5 Accepted 33ms 828.0 KiB
#6 Accepted 34ms 596.0 KiB
#7 Accepted 39ms 560.0 KiB
#8 Accepted 60ms 588.0 KiB
#9 Accepted 37ms 564.0 KiB

Code

#include<bits/stdc++.h>
using namespace  std;
using ll = long long;
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        map<char,ll>mp;
        string s; cin >> s;
        for(int i = 0; i < n; i++) {
            mp[s[i]]++;
        }

        ll ans = 0;
        for (auto u : mp) {
            if(u.second > 1) {
                int x = u.second;
                ans += 1LL * x * (x - 1);
            }
        }

        cout << ans << '\n';
    }
    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:32:29
Judged At
2024-10-03 13:51:48
Judged By
Score
100
Total Time
60ms
Peak Memory
1.547 MiB