結果

問題 No.2419 MMA文字列2
ユーザー u-shou-sho
提出日時 2023-08-12 15:16:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 207,056 KB
実行使用メモリ 31,232 KB
最終ジャッジ日時 2024-04-30 08:42:55
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 15 ms
9,244 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 29 ms
14,788 KB
testcase_15 AC 16 ms
10,272 KB
testcase_16 AC 26 ms
15,304 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 28 ms
15,820 KB
testcase_19 AC 29 ms
16,204 KB
testcase_20 AC 11 ms
7,304 KB
testcase_21 AC 7 ms
6,940 KB
testcase_22 AC 36 ms
30,044 KB
testcase_23 AC 35 ms
30,036 KB
testcase_24 AC 33 ms
30,024 KB
testcase_25 AC 33 ms
29,984 KB
testcase_26 AC 6 ms
6,944 KB
testcase_27 AC 32 ms
29,976 KB
testcase_28 AC 64 ms
31,232 KB
testcase_29 AC 61 ms
30,160 KB
testcase_30 AC 59 ms
30,060 KB
testcase_31 AC 61 ms
29,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;


/* nC2 */
[[nodiscard]] uint64_t comb2(uint64_t n) {
    //--------Valid Error------------------
    if (n < 2ULL) return 0ULL;
    //-------------------------------------

    uint64_t retVal;
    if (n%2) retVal = n*((n-1ULL)/2ULL);
    else retVal = (n/2ULL)*(n-1ULL); 
    return retVal;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;
    vector<vector<uint>> cco(1, vector<uint>(26, 0));
    for (const auto &Si: S){
        cco.push_back(cco.back()); // 間に合わなかったらwavelet treeにする
        cco.back().at(Si-'A') += 1;
    }

    // 末尾から、これを3文字目としてMMA文字列を作る個数を数える。
    uint64_t ans = 0;
    for(uint i = cco.size()-2; i>=2; i--){
        const uint Si = S[i]-'A';
        for(uint c = 0; c<26; c++){
            if (Si == c) continue;
            ans += comb2(cco[i][c]);
            // if (comb2(cco[i][c])) cout << i << ',' << c << ':' << ans << S[i]<<Si << '\n';
        }
    }

    cout << ans << '\n';

    return 0;
}
0