結果

問題 No.2419 MMA文字列2
ユーザー marble72
提出日時 2023-08-12 15:24:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 176,540 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-20 02:03:42
合計ジャッジ時間 3,237 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int l = S.length();
    vector<int> dp(l+1,0);
    map<char,int> ser;
    ser[S[0]]++;
    ser[S[1]]++;
    if(S[0] == S[1] && S[2] != S[1]){
        dp[3] = 1;
    }
    ll next = 0;
    for(int i=4;i<=l;i++){
        int x = ser[S[i-2]];
        if(x != 0){
            if(S[i-1] == S[i-2]){
                dp[i] += x;
            }else{
                dp[i]+=x+next;
                next = 0;
            }
        }
        ser[S[i-2]]++;
        int y = ser[S[i-1]];
        if(y >= 2){
            ll down = y*(y-1)/2;
            dp[i]+=dp[i-1]-down;
            next = down;
        }else{
            dp[i] += dp[i-1];
        }
    }
    for(int i=1;i<=l;i++){
        dp[i] += dp[i-1];
    }
    cout << dp[l] << endl;
}
0