結果

問題 No.672 最長AB列
ユーザー aaaaaaiu
提出日時 2019-08-20 15:26:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 372 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 200,796 KB
最終ジャッジ日時 2025-01-07 14:19:39
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    string s;
    cin>>s;
    map<int,int> mp;
    int a=0;
    int ans=0;
    mp[0]=-1;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='A') a++;
        else a--;
        if (mp.find(a)!=mp.end()) ans=max(ans,i-mp[a]);
        else mp[a]=i;
    }
    cout<<ans<<endl;
    return 0;
}
0