/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 6ms 1.559 MiB
#3 Wrong Answer 6ms 1.57 MiB

Code

#include <iostream>
#include <string>

using namespace std;

void solve() {
    int n; cin >> n;    
    string s; cin >> s; 
    int cnt[26] = {0}; // Ensure cnt is zero-initialized
    int ans = 0;    
    for(auto& ch : s) { 
        cnt[ch - 'a']++;
    }
    for(int i = 0; i < 26; i++) {   
        ans += cnt[i] * (cnt[i] - 1);
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1038 Do not touch my string
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 23:40:06
Judged At
2024-11-11 02:39:43
Judged By
Score
10
Total Time
6ms
Peak Memory
1.57 MiB