/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 7ms 1.469 MiB
#3 Accepted 7ms 1.496 MiB
#4 Accepted 25ms 788.0 KiB
#5 Accepted 33ms 760.0 KiB
#6 Accepted 33ms 604.0 KiB
#7 Accepted 37ms 600.0 KiB
#8 Accepted 58ms 572.0 KiB
#9 Accepted 36ms 580.0 KiB

Code

#include <bits/stdc++.h>

#define endl '\n'
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template<typename T>
void scan(vector<T> &v) {for (T &x : v) cin >> x;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LUCHADOR
    freopen("/home/joker/Documents/code/in", "r", stdin);
    freopen("/home/joker/Documents/code/out", "w", stdout);
#endif

    int t;
    cin >> t;

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

        string s;
        cin >> s;

        map<char, int> pos;
        for (char &c : s) {
            pos[c]++;
        }

        ll ways = 0LL;
        for (auto &[_, c] : pos) {
            ways += 1LL * (c - 1) * c;
        }

        cout << ways << endl;
    }

    return 0;
}

// 1 3, 3 1

// 1 2 3
// 1 2
// 1 3
// 2 3

// 1 2 3 4
// 1 2
// 1 3
// 1 4
// 2 3
// 2 4
// 3 4

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 16:36:06
Judged At
2024-10-03 13:49:57
Judged By
Score
100
Total Time
58ms
Peak Memory
1.496 MiB