結果
| 問題 | No.2419 MMA文字列2 | 
| コンテスト | |
| ユーザー |  くけ | 
| 提出日時 | 2023-08-12 14:08:27 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 2,000 ms | 
| コード長 | 648 bytes | 
| コンパイル時間 | 4,109 ms | 
| コンパイル使用メモリ | 251,588 KB | 
| 最終ジャッジ日時 | 2025-02-16 04:16:21 | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
int main(){
    string s ;
    cin >> s ;
    vector<ll> G[26] ; 
    rep(i,s.size()){
        G[s[i]-'A'].push_back(i) ;
    }
    ll ans = 0 ;
    rep(i,26){
        ll n , m ;
        n = m = G[i].size() ;
        rep(j,n){
            if( n-j-2 < 0 ) continue;
            ll a = G[i][n-j-1] ;
            ans += ( s.size() - j - 1 - a ) * ( m - 1 ) ;
            m-- ;
        }
    }
    cout << ans << endl ;
}
            
            
            
        