Submission #51308306


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define repl(i,a,b) for(ll i = a; i < b; i++)
#define fore(i,a) for(auto &i : a)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if(b < a){ a = b; return 1; } return 0; }

void pri() { printf("\n"); }
void pri(int X) { printf("%d", X); }
void pri(long long X) { printf("%lld", X); }
void pri(double X) { printf("%.12lf", X); }
void pri(long double X) { printf("%.12Lf", X); }
void pri(size_t X) { printf("%zd", X); }
void pri(bool X) { printf("%d", (int)X); }
void pri(char X) { printf("%c", X); }
void pri(string X) { printf("%s", X.c_str()); }
template<class T, class U>void pri(pair<T, U> X) { pri(X.first); printf(" "); pri(X.second); }
template<class T>void pri(vector<T> X) { rep(i,0,(int)X.size()){ if(i){ printf(" "); } pri(X[i]); }}
template<class T>void pri(vector<vector<T>> X) { rep(i,0,(int)X.size()){ if(i){ printf("\n"); } pri(X[i]); }}
void prin() {}
template <class Head, class... Tail>void prin(Head&& head, Tail&&... tail) {
    pri(head); printf("\n"); prin(forward<Tail>(tail)...);
}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll MOD = 1000000007;
const int INF = INT_MAX/2;
const ll INFL = LLONG_MAX/2;



int main() {
    string S; cin >> S;
    
    ll N = S.size();
    
    
    map<char, ll> m;
    rep(i,0,N) m[S[i]]++;
    
    
    bool Flag = 0;
    ll Ans = N*(N-1)/2;
    
    fore(M, m) {
        if(1 < M.second) Flag = 1;
        Ans -= M.second * (M.second-1) / 2;
    }
    
    Ans += (ll)Flag;
    
    prin(Ans);
}

Submission Info

Submission Time
Task C - One Time Swap
User BattleCats
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1828 Byte
Status AC
Exec Time 34 ms
Memory 5400 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 3760 KiB
example_01.txt AC 1 ms 3696 KiB
hand_00.txt AC 15 ms 5400 KiB
hand_01.txt AC 1 ms 3760 KiB
hand_02.txt AC 1 ms 3828 KiB
hand_03.txt AC 1 ms 3832 KiB
hand_04.txt AC 1 ms 3752 KiB
hand_05.txt AC 16 ms 5392 KiB
hand_06.txt AC 16 ms 5244 KiB
random_00.txt AC 1 ms 3828 KiB
random_01.txt AC 1 ms 3892 KiB
random_02.txt AC 1 ms 3632 KiB
random_03.txt AC 1 ms 3760 KiB
random_04.txt AC 1 ms 3824 KiB
random_05.txt AC 34 ms 5336 KiB
random_06.txt AC 34 ms 5256 KiB
random_07.txt AC 34 ms 5244 KiB
random_08.txt AC 34 ms 5256 KiB
random_09.txt AC 33 ms 5184 KiB
random_10.txt AC 34 ms 5332 KiB
random_11.txt AC 34 ms 5332 KiB
random_12.txt AC 34 ms 5256 KiB
random_13.txt AC 34 ms 5232 KiB
random_14.txt AC 34 ms 5276 KiB