結果
| 問題 | No.2419 MMA文字列2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-07-26 12:57:44 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 72 ms / 2,000 ms | 
| コード長 | 619 bytes | 
| コンパイル時間 | 1,701 ms | 
| コンパイル使用メモリ | 197,420 KB | 
| 最終ジャッジ日時 | 2025-02-15 19:13:11 | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int n = s.size();
    long long ans = 0;
    vector<vector<long long>> sum(n + 1, vector<long long>(26));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 26; j++){
            sum[i + 1][j] += sum[i][j];
        }
        sum[i + 1][s[i] - 'A']++;
    }
    for(int i = n - 1; i >= 0; i--){
        for(int j = 0; j < 26; j++){
            if(s[i] - 'A' == j) continue;
            ans += sum[i][j] * (sum[i][j] - 1) / 2;
        }
    }
    cout << ans << "\n";
}
            
            
            
        