/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Wrong Answer 20ms 1.461 MiB
#3 Wrong Answer 20ms 1.625 MiB
#4 Accepted 18ms 828.0 KiB
#5 Accepted 18ms 768.0 KiB
#6 Accepted 18ms 816.0 KiB
#7 Accepted 22ms 584.0 KiB
#8 Accepted 57ms 600.0 KiB
#9 Wrong Answer 44ms 572.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]++;
        }

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

        bool allSame = true;
        for (int i = 1; i < n; ++i) {
            if (s[i] != s[0]) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            totalSwaps = (n * (n - 1)) / 2;
        }

        cout << totalSwaps << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 17:03:32
Judged At
2024-10-03 13:49:16
Judged By
Score
60
Total Time
57ms
Peak Memory
1.625 MiB