結果

問題 No.2419 MMA文字列2
ユーザー bortik
提出日時 2023-08-16 04:20:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 193,980 KB
最終ジャッジ日時 2025-02-16 08:39:13
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--)

void solve(){
    string s; cin >> s;
    unsigned long long ans = 0;
    vector<ll> app(26,0);
    int l = s.size();
    rep(i,0,l){
        int ind = (int)s[i]-(int)'A';
        app[ind]++;
        rep(j,0,26){
            if(j != ind && app[j] >= 2){
                ans += app[j]*(app[j]-1)/2;
            }
        }
    }

    cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();

    return 0;
}
0