/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 25ms 2.355 MiB
#3 Accepted 24ms 2.664 MiB
#4 Accepted 22ms 736.0 KiB
#5 Accepted 22ms 748.0 KiB
#6 Accepted 21ms 320.0 KiB
#7 Accepted 24ms 324.0 KiB
#8 Accepted 44ms 552.0 KiB
#9 Accepted 33ms 556.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

int main(){
  int t;
  cin >> t;
  while (t--){
    ll n, ans = 0;
    string s;
    vector<ll> a(26);
    cin >> n >> s;
    for (int i = 0; i < n; i++){
      a[s[i] - 97]++;
    }
    for (int i = 0; i < 26; i++){
      ans += (a[i] * (a[i] - 1));
    }
    cout << ans << endl;
  }
}

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 15:53:52
Judged At
2024-11-11 03:33:43
Judged By
Score
100
Total Time
44ms
Peak Memory
2.664 MiB