/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 29ms 580.0 KiB
#3 Accepted 27ms 540.0 KiB
#4 Accepted 29ms 788.0 KiB
#5 Accepted 27ms 540.0 KiB
#6 Accepted 28ms 540.0 KiB
#7 Accepted 31ms 552.0 KiB
#8 Accepted 29ms 772.0 KiB
#9 Accepted 17ms 796.0 KiB

Code

// BISMILLAH

#include "bits/stdc++.h"

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 500005, inf = 1000000005;

signed main() {
	// fastIO;
	int testCases=1;
	scanf("%lld",&testCases);
	// std::cin >> testCases;
	
	for (int T = 1; T <= testCases; T++) {
        int N;
        scanf("%d ", &N);
        int a[26] = {0};
        for (int i = 0; i < N; i++) {
            char c;
            scanf("%c", &c);
            a[c-'a'] += 1;
        }
        ll ans = 0;
        for (int i = 0; i < 26; i++) {
            ans += (ll)a[i] * (a[i] - 1);
        }
        printf("%lld\n", ans);
    }
	
	return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-07 10:21:02
Judged At
2024-05-07 10:21:02
Judged By
Score
100
Total Time
31ms
Peak Memory
796.0 KiB