結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false


int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    string S;
    cin >> S;
    ll N = S.size();

    //0~iまでで文字jはいくつあるか
    ll dp1[26] = {};

    //0~iまでで重複する文字jはいくつあるか
    ll dp2[26] = {};

    ll dp2sum = 0;

    ll Ans = 0;

    REP(i,N){
        if(i==0){
            dp1[S[i]-'A']++;
            continue;
        }

        /*ll tmp1[26], tmp2[26];

        REP(j,26){tmp1[j]+=dp1[j];}
        REP(j,26){tmp2[j]+=dp2[j];}*/

        int c = S[i]-'A';

        dp2[c]+=dp1[c];
        dp2sum+=dp1[c];
        dp1[c]++;

        Ans += (dp2sum-dp2[c]);

        /*REP(j,26){cout << (char)('A'+j) << " ";}cout << endl;
        REP(j,26){cout << dp1[j] << " ";}cout << endl;
        REP(j,26){cout << dp2[j] << " ";}cout << endl;
        cout << Ans << endl << endl;*/

        /*swap(dp1,tmp1);
        swap(dp2,tmp2);*/

    }

    cout << Ans << endl;

    
    return 0;
}
0