/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 6ms 1.777 MiB
#3 Accepted 6ms 1.426 MiB
#4 Accepted 4ms 808.0 KiB
#5 Accepted 4ms 776.0 KiB
#6 Accepted 3ms 536.0 KiB
#7 Accepted 3ms 576.0 KiB
#8 Accepted 6ms 580.0 KiB
#9 Accepted 6ms 764.0 KiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define ll long long

template<typename T> T nPr(T n, T r) {
    T sum = 1;
    for(T i = 1; i <= r; i++) {
        sum = sum * (n - r + i);
    }
    return sum;
}

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        int n;
        cin >> n;
        string s;
        cin >> s;
        vector<ll> a(26, 0);
        for(auto i : s) {
            a[i - 'a']++;
        }
        ll ans = 0;
        for (int i = 0; i < 26; i++) {
            if(a[i] > 1) {
                ans += nPr(a[i], 2LL);
            }
        }
        cout << ans << nl;
    }

    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:17:03
Judged At
2024-11-11 03:34:49
Judged By
Score
100
Total Time
6ms
Peak Memory
1.777 MiB