/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 15ms 1.469 MiB
#3 Accepted 14ms 1.504 MiB
#4 Accepted 14ms 740.0 KiB
#5 Accepted 14ms 792.0 KiB
#6 Accepted 14ms 808.0 KiB
#7 Accepted 17ms 568.0 KiB
#8 Accepted 50ms 592.0 KiB
#9 Accepted 41ms 596.0 KiB

Code

#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        unordered_map<char, int> charCount;
        for (char c : s) {
            charCount[c]++;
        }

        long long totalSwaps = 0;
        for (auto& entry : charCount) {
            long long count = entry.second;
            if (count > 1) {
                totalSwaps += (count * (count - 1)) ;
            }
        }

        cout << totalSwaps << 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 17:28:14
Judged At
2024-10-03 13:48:35
Judged By
Score
100
Total Time
50ms
Peak Memory
1.504 MiB