/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 356.0 KiB
#2 Runtime Error 19ms 1.879 MiB
#3 Runtime Error 18ms 1.664 MiB

Code

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define vch vector<char>
#define vstr vector<string>
#define vcust vector<custom>
#define u_set unordered_set
#define sint set<int>
#define sch set<char>
#define u_map unordered_map
#define pii pair<int, int>
#define vpii vector<pii>
#define mii map<int, int>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x) 
#define trail_zero(x) __builtin_ctz(x) 
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define nl cout << '\n';
using namespace std;
int cerrr = 1;
#define err cerr << "Thats GFG! " << cerrr++ << '\n'
const ll Inf = 0x3fffffffffffffff;
const int mod = 0x3b9aca07;

void debug_mode()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

struct custom
{
    int a;
    char b;
    string c;
};

int factorial(int n) {
    int prod = 1ll;
    for(int i = 1; i <= n; i++) prod *= i;
    return prod;
}
int permutation(int n, int r) {
    return (factorial(n) / factorial(n - r));
}
void solve();
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    // debug_mode();
    // fileIO();
    int TestCase = 1;
    cin >> TestCase;
    int case_no = 1;
    while (TestCase--)
    {
        // cout << "Case " << case_no++ << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
}

void solve()
{
    int n; cin >> n;
    string txt; cin >> txt;
    u_map<char, int> freq;
    int count = 0ll;
    for(auto &&i : txt) freq[i]++;
    for(auto &&i : freq){
        if(i.se > 1){
            count += permutation(i.se, 2);;
        }
    }
    cout << count << '\n';
}

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:54:17
Judged At
2024-11-11 03:33:42
Judged By
Score
10
Total Time
19ms
Peak Memory
1.879 MiB