/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 592.0 KiB
#2 Wrong Answer 116ms 1.48 MiB
#3 Wrong Answer 118ms 1.492 MiB

Code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector <char> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    sort (v.begin(), v.end());

    char p = v[0];
    int count = 0;
    long long sum = 0;
    for (int i = 1; i < n; i++)
    {
        if (p == v[i]) count++;
        else
        {
            p = v[i];
            sum += count * (count + 1);
            count = 0;
        }
    }
    sum += count * (count + 1);
    cout << sum << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    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 15:55:56
Judged At
2024-11-11 03:33:40
Judged By
Score
10
Total Time
118ms
Peak Memory
1.492 MiB