結果

問題 No.672 最長AB列
ユーザー Naco
提出日時 2019-10-21 17:23:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 173,644 KB
実行使用メモリ 13,692 KB
最終ジャッジ日時 2024-07-02 17:47:16
合計ジャッジ時間 2,612 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    string s; cin >> s;
    int N=s.size();
    int cnt[N+1]={};
    for(int i=0;i<N;i++){
        if(s[i]=='A') cnt[i]++;
        else cnt[i]--;
    }
    for(int i=1;i<N;i++){
        cnt[i]+=cnt[i-1];
    }
    map<int,int> m;
    for(int i=0;i<N;i++){
        m[cnt[i]]=i;
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans=max(m[cnt[i]]-i,ans);
    }
    cout << ans << endl;
}
0