結果

問題 No.2419 MMA文字列2
ユーザー hitonihikihitonihiki
提出日時 2023-08-12 14:57:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,001 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 172,280 KB
実行使用メモリ 100,464 KB
最終ジャッジ日時 2024-04-30 07:37:40
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    ll n = S.length();
    // 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;
    }
    // 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]++;
    }

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

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

        ll score = n - i - 1;
        ll tmp = sum[i][index] - (num[n - 1][index] - num[i][index]);
        ans += tmp;
    }

    cout << ans << endl;
}
0