/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 15ms 1.422 MiB
#3 Accepted 15ms 1.625 MiB
#4 Accepted 14ms 708.0 KiB
#5 Accepted 14ms 788.0 KiB
#6 Accepted 14ms 596.0 KiB
#7 Accepted 17ms 596.0 KiB
#8 Accepted 52ms 596.0 KiB
#9 Accepted 42ms 564.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-11-11 03:32:12
Judged By
Score
100
Total Time
52ms
Peak Memory
1.625 MiB