結果

問題 No.2419 MMA文字列2
ユーザー hitonihikihitonihiki
提出日時 2023-08-12 15:18:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 172,484 KB
実行使用メモリ 100,384 KB
最終ジャッジ日時 2024-04-30 08:49:16
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 26 ms
24,960 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 50 ms
44,928 KB
testcase_15 AC 31 ms
28,928 KB
testcase_16 AC 52 ms
46,976 KB
testcase_17 AC 16 ms
16,384 KB
testcase_18 AC 54 ms
48,836 KB
testcase_19 AC 55 ms
50,304 KB
testcase_20 AC 17 ms
17,920 KB
testcase_21 AC 10 ms
13,696 KB
testcase_22 AC 116 ms
100,352 KB
testcase_23 AC 116 ms
100,256 KB
testcase_24 AC 120 ms
100,280 KB
testcase_25 AC 114 ms
100,384 KB
testcase_26 AC 13 ms
14,976 KB
testcase_27 AC 114 ms
100,320 KB
testcase_28 AC 119 ms
100,236 KB
testcase_29 AC 116 ms
100,348 KB
testcase_30 AC 116 ms
100,256 KB
testcase_31 AC 118 ms
100,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    string S;
    cin >> S;

    ll n = S.length();
    // i 文字目までのアルファベットの個数
    vector<vector<ll>> num(n, vector<ll>(26));
    num[0][S[0] - 'A'] = 1;
    for (ll i = 1; i < n; ++i) {
        for (ll j = 0; j < 26; ++j) num[i][j] = num[i - 1][j];

        ll index = S[i] - 'A';
        num[i][index]++;
    }

    // i 文字目を MMA の二文字目としたときの MMA の総数
    vector<vector<ll>> sum(n, vector<ll>(26));
    for (ll i = n - 2; i >= 0; --i) {
        for (ll j = 0; j < 26; ++j) sum[i][j] = sum[i + 1][j];

        ll index = S[i] - 'A';
        sum[i][index] += n - i - 1 - (num[n - 1][index] - num[i][index]);
    }

    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        ll index = S[i] - 'A';

        if (num[i][index] == 1) continue;

        ans += sum[i][index];
    }

    cout << ans << endl;
}
0