結果

問題 No.2419 MMA文字列2
ユーザー ryota2357ryota2357
提出日時 2023-07-12 15:48:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 75,648 KB
最終ジャッジ日時 2023-10-12 06:05:08
合計ジャッジ時間 4,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 25 ms
19,548 KB
testcase_13 AC 4 ms
5,816 KB
testcase_14 AC 45 ms
34,404 KB
testcase_15 AC 29 ms
22,448 KB
testcase_16 AC 49 ms
35,640 KB
testcase_17 AC 13 ms
12,936 KB
testcase_18 AC 50 ms
37,232 KB
testcase_19 AC 51 ms
38,240 KB
testcase_20 AC 14 ms
14,252 KB
testcase_21 AC 10 ms
10,832 KB
testcase_22 AC 102 ms
75,632 KB
testcase_23 AC 100 ms
75,580 KB
testcase_24 AC 97 ms
75,640 KB
testcase_25 AC 97 ms
75,648 KB
testcase_26 AC 10 ms
11,892 KB
testcase_27 AC 96 ms
75,616 KB
testcase_28 AC 100 ms
75,636 KB
testcase_29 AC 99 ms
75,600 KB
testcase_30 AC 100 ms
75,596 KB
testcase_31 AC 99 ms
75,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

void assert_str(string& s) {
    assert(3 <= s.length() && s.length() <= 200000);
    for (auto c : s) {
        assert('A' <= c && c <= 'Z');
    }
}

int main() {
    string s;
    cin >> s;
    assert_str(s);

    int n = s.length();
    vector cnt_sum('Z' + 1, vector<int>(n + 1));
    for (int i = 0; i < n; ++i) {
        cnt_sum[s[i]][i + 1] += 1;
        for (char c = 'A'; c <= 'Z'; ++c) {
            cnt_sum[c][i + 1] += cnt_sum[c][i];
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (char c = 'A'; c <= 'Z'; ++c) {
            if (s[i] == c) {
                continue;
            }
            ll cnt = cnt_sum[c][i];
            ans += cnt * (cnt - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}
0