Submission #51377155


Source Code Expand

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

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    std::string s;
    is >> s;

    const Num size = s.size();
    std::map<char, Num> table;
    for(const auto& c : s) {
        table[c] += 1;
    }

    Num n_combi = (size * (size - 1)) / 2;
    Num n_sames {0};
    for(const auto& [k,v] : table) {
        n_sames += (v * (v-1)) / 2;
    }

    Num ans = n_combi - n_sames + (n_sames > 0);
    os << ans << "\n";
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task C - One Time Swap
User zettsut
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1112 Byte
Status AC
Exec Time 35 ms
Memory 5332 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 3556 KiB
example_01.txt AC 1 ms 3516 KiB
hand_00.txt AC 14 ms 5236 KiB
hand_01.txt AC 1 ms 3444 KiB
hand_02.txt AC 1 ms 3696 KiB
hand_03.txt AC 1 ms 3568 KiB
hand_04.txt AC 1 ms 3560 KiB
hand_05.txt AC 17 ms 5312 KiB
hand_06.txt AC 16 ms 5236 KiB
random_00.txt AC 1 ms 3520 KiB
random_01.txt AC 1 ms 3636 KiB
random_02.txt AC 1 ms 3440 KiB
random_03.txt AC 1 ms 3568 KiB
random_04.txt AC 1 ms 3516 KiB
random_05.txt AC 33 ms 5292 KiB
random_06.txt AC 34 ms 5160 KiB
random_07.txt AC 33 ms 5244 KiB
random_08.txt AC 33 ms 5236 KiB
random_09.txt AC 35 ms 5208 KiB
random_10.txt AC 33 ms 5164 KiB
random_11.txt AC 33 ms 5244 KiB
random_12.txt AC 33 ms 5332 KiB
random_13.txt AC 33 ms 5244 KiB
random_14.txt AC 33 ms 5240 KiB