結果

問題 No.672 最長AB列
ユーザー ts_
提出日時 2018-04-15 05:37:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 160,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-27 20:12:23
合計ジャッジ時間 2,055 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint a[410001];
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int cur=200000;
    rep(i,400001) a[i]={-1,-1};
    a[cur].first=0;
    rep(i,n){
        if(s[i]=='A') ++cur;
        else --cur;
        if(a[cur].first==-1) a[cur].first=i+1;
        else a[cur].second=i+1;
    }
    int mx=0;
    rep(i,400001)if(a[i].second!=-1)mx=max(mx,a[i].second-a[i].first);
    cout<<mx<<endl;
    return 0;
}
0