結果

問題 No.2419 MMA文字列2
ユーザー ryota2357ryota2357
提出日時 2023-07-12 15:49:44
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 879 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 87,628 KB
実行使用メモリ 75,732 KB
最終ジャッジ日時 2023-10-12 06:06:50
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 25 ms
19,508 KB
testcase_13 AC 5 ms
5,808 KB
testcase_14 AC 45 ms
34,296 KB
testcase_15 AC 29 ms
22,404 KB
testcase_16 AC 47 ms
35,636 KB
testcase_17 AC 12 ms
12,900 KB
testcase_18 AC 50 ms
37,216 KB
testcase_19 AC 49 ms
38,268 KB
testcase_20 AC 13 ms
14,248 KB
testcase_21 AC 10 ms
10,856 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 10 ms
11,880 KB
testcase_27 AC 100 ms
75,628 KB
testcase_28 AC 101 ms
75,592 KB
testcase_29 AC 102 ms
75,640 KB
testcase_30 AC 100 ms
75,604 KB
testcase_31 AC 102 ms
75,604 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;
            }
            int cnt = cnt_sum[c][i];
            ans += cnt * (cnt - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}
0