Submission #51315688


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define N 100007
#define all(x) x.begin(),x.end()
ll binmultiply(ll a,ll b,ll m){ll res=0;while(b>0){if(b&1)res=(res+a)%m;a=(a+a)%m;b=b>>1;}return res;}
ll expo(ll a, ll b, ll m) {ll res = 1; while (b > 0) {if (b & 1)res = binmultiply(res,a,m)% m; a = binmultiply(a,a,m) % m; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
    
    
void solve()
{
    string s;cin >> s;
    int n=s.size();
    ll ans = n*(n-1)/2;
    vector<int> f(26,0);
    for(int i=0;i<n;i++){
        f[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        ans -= (f[i]*(f[i]-1))/2;
    }
    for(int i=0;i<26;i++) if(f[i]>1) {ans++;break;}
    cout << ans << endl;
    // set<string> st;
    // for(int i=0;i<n;i++){
    //     for(int j=i+1;j<n;j++){
    //         swap(s[i],s[j]);
    //         st.insert(s);
    //         swap(s[i],s[j]);
    //     }
    // }
    // cout << st.size() << endl;
}
    
    
int32_t main()
{
    IOS;
    ll t=1;
    //cin >> t;
    while(t--)
        {
            solve();
        }
    return 0;
}

Submission Info

Submission Time
Task C - One Time Swap
User Rohith16
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1651 Byte
Status AC
Exec Time 4 ms
Memory 4200 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 2
AC × 24
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3456 KiB
example_01.txt AC 1 ms 3456 KiB
hand_00.txt AC 4 ms 4172 KiB
hand_01.txt AC 1 ms 3500 KiB
hand_02.txt AC 1 ms 3528 KiB
hand_03.txt AC 1 ms 3596 KiB
hand_04.txt AC 1 ms 3524 KiB
hand_05.txt AC 3 ms 4164 KiB
hand_06.txt AC 4 ms 4128 KiB
random_00.txt AC 1 ms 3396 KiB
random_01.txt AC 1 ms 3412 KiB
random_02.txt AC 1 ms 3608 KiB
random_03.txt AC 1 ms 3448 KiB
random_04.txt AC 1 ms 3452 KiB
random_05.txt AC 3 ms 4140 KiB
random_06.txt AC 3 ms 4192 KiB
random_07.txt AC 3 ms 4200 KiB
random_08.txt AC 3 ms 4120 KiB
random_09.txt AC 3 ms 4196 KiB
random_10.txt AC 3 ms 4148 KiB
random_11.txt AC 3 ms 4080 KiB
random_12.txt AC 3 ms 4124 KiB
random_13.txt AC 3 ms 4048 KiB
random_14.txt AC 3 ms 4120 KiB