/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 22ms 2.355 MiB
#3 Accepted 22ms 2.301 MiB
#4 Accepted 19ms 748.0 KiB
#5 Accepted 19ms 760.0 KiB
#6 Accepted 18ms 532.0 KiB
#7 Accepted 21ms 548.0 KiB
#8 Accepted 41ms 580.0 KiB
#9 Accepted 32ms 324.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-10-03 13:51:16
Judged By
Score
100
Total Time
41ms
Peak Memory
2.355 MiB